Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create Triangular imageview in objective C

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.31k
    Comment on it

    Here is the code for creating the triangular uiimageview -

        UIBezierPath *bzrPath = [UIBezierPath new];
        [bzrPath moveToPoint:(CGPoint){0, self.imgView.frame.size.height}];
        [bzrPath addLineToPoint:(CGPoint){80, 0}];
        [bzrPath addLineToPoint:(CGPoint){160, self.imgView.frame.size.height}];
        [bzrPath closePath];
        
        // 2. Create a CAShapeLayer with this triangular path
        // Same size as the original imageView
        CAShapeLayer *mask = [CAShapeLayer new];
        mask.frame = self.imgView.bounds;
        mask.path = bzrPath.CGPath;
        
        // 3. Mask the imageView's layer with this shape
        self.imgView.layer.mask = mask;
        self.imgView.layer.borderWidth=2.0f;
        self.imgView.layer.borderColor=(__bridge CGColorRef _Nullable)([UIColor blackColor]);

    We can change the coordinates i.e. width and height of imageview according to the requirement. and then load the image in the imageview.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: