Change the default shape of a UIImageview shape rectangle

Now I am developing a project in that I need to show an image with a frame, as shown below.

enter image description here

How can i do this? I am not going to do this. Please solve any idea.

+7
ios objective-c uiimageview
source share
2 answers

Perhaps this code will help you ...

UIBezierPath *maskPath; maskPath = [UIBezierPath bezierPathWithRoundedRect:YourImageVIew.bounds byRoundingCorners:(UIRectCornerTopRight | UIRectCornerBottomRight) cornerRadii:CGSizeMake(50.0, 50.0)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = YourImageVIew.bounds; maskLayer.path = maskPath.CGPath; YourImageVIew.layer.mask = maskLayer; 
+9
source share

Here's how you can create a masking path:

 - (UIBezierPath *)curvedRectWithFrame:(CGRect)frame radius:(CGFloat)radius { double halfFrameHeight = ((double)frame.size.height / 2); // Check if the radius is too small. if (radius < halfFrameHeight) { radius = halfFrameHeight; } CGFloat arcAngle = asin(halfFrameHeight/radius); CGFloat centerX = frame.origin.x + (frame.size.width - radius); CGFloat centerY = frame.origin.y + halfFrameHeight; UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:frame.origin]; [path addLineToPoint:CGPointMake(centerX + radius * cos(arcAngle), frame.origin.y)]; [path addArcWithCenter:CGPointMake(centerX, centerY) radius:radius startAngle:-arcAngle endAngle:arcAngle clockwise:YES]; [path addLineToPoint:CGPointMake(frame.origin.x, path.currentPoint.y)]; [path closePath]; return path; } 

Then you can apply a shape mask to your image:

 const CGFloat kCurveRadius = 500.; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = yourImageView.bounds; maskLayer.path = [self curvedRectWithFrame:maskLayer.bounds radius:kCurveRadius].CGPath; yourImageView.layer.mask = maskLayer; 
+1
source share

All Articles