Search code examples
androidandroid-layoutios7android-shape

How to create a custome shape in which image could be displayed?


In a project I have to show profile image and other images in a different shape. I don't know how to create a shape like it, and how to show an image in it. I have to put this type of shape in list view also. Please suggest me.

Thanks in advance.


Solution

  • Try something like that:

    profileImageview=[[UIImageView alloc]initWithFrame:CGRectMake(2,10,100,80)];
        UIBezierPath *path = [UIBezierPath new];
        [path moveToPoint:(CGPoint){0, 0}];
        [path addLineToPoint:(CGPoint){100, 0}];
        [path addLineToPoint:(CGPoint){70, 80}];
        [path addLineToPoint:(CGPoint){0, 80}];
        [path addLineToPoint:(CGPoint){0, 0}];
    
         CAShapeLayer *mask = [CAShapeLayer new];
        mask.frame = profileImageview.bounds;
        mask.path = path.CGPath;
    
        // Mask the imageView's layer with this shape
        profileImageview.layer.mask = mask;