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)