I want to draw a UIImageView
in oval shape. i try to draw but i cloud not find answer. i show most of round or circle shape.
enter link description here
i try this but this is not work
#import <QuartzCore/QuartzCore.h>`
CALayer *imageLayer = YourImageview.layer;
[imageLayer setCornerRadius:5];
[imageLayer setBorderWidth:1];
[imageLayer setMasksToBounds:YES];
If you want to draw an imageview in an oval shape, follow below steps:
Create a UIBezierPath using bezierPathWithOvalInRect
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:YOUR_RECT];
Create a mask layer by using CAShapeLayer
CAShapeLayer *maskLayer = [CAShapeLayer layer];
Now set the bezier path as mask layer's path
maskLayer.path = path.CGPath;
Then we are going mask our view with our own mask layer.
YourImageview.layer.mask = maskLayer;
That's all. Try it.
Yes, you can done it by draw BezierPath but even we can't get exact round-rect image... so i'll give you other trick... you use 2 imageview one for main-imageview in which you pass your image.. second(overhead imageviw) for round or circle shape image with orange color border which is transparent in middle/center.
when you use overheadimageview over main imageview then you can find exact round or circle shape image
You need to have a corner Radius half of what your image size is, to draw the cricular.
But to draw oval shape you need smaller radius.
CGFloat imgSize = 55;
UIImageView *imgViewProfile = [[UIImageView alloc] init];
imgViewProfile.frame = CGRectMake(5, 5, imgSize, imgSize);
imgViewProfile.layer.cornerRadius = imgSize / 2;
imgViewProfile.clipsToBounds = YES;
imgViewProfile.contentMode = UIViewContentModeScaleAspectFill;
[view addSubview:imgViewProfile];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.