I have a UIImageView
on each of my UITableView
cells, that display a remote image (using SDWebImage
). I\'ve done some QuartzCore
Set the height & width of the of the UIImageView to be the same e.g.:Height=60
& Width = 60
, then the cornerRadius
should be exactly the half.I have kept it 30 in my case.It worked for me.
self.imageView.layer.cornerRadius = 30;
self.imageView.layer.borderWidth = 3;
self.imageView.layer.borderColor = [UIColor whiteColor].CGColor;
self.imageView.layer.masksToBounds = YES;
Use this code.. This will be helpful..
UIImage* image = ...;
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0);
// Add a clip before drawing anything, in the shape of an rounded rect
[[UIBezierPath bezierPathWithRoundedRect:imageView.bounds
cornerRadius:50.0] addClip];
// Draw your image
[image drawInRect:imageView.bounds];
// Get the image, here setting the UIImageView image
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
// Lets forget about that we were drawing
UIGraphicsEndImageContext();
It works fine for me. :)
Usable solution in Swift
using extension
:
extension UIView{
func circleMe(){
let radius = CGRectGetWidth(self.bounds) / 2
self.layer.cornerRadius = radius
self.layer.masksToBounds = true
}
}
Usage:
self.venueImageView.circleMe()
In swift, inside your viewDidLoad
method, with the userImage
outlet:
self.userImage.layer.borderWidth = 1;
self.userImage.layer.borderColor = UIColor.whiteColor().CGColor;
self.userImage.layer.cornerRadius = self.userImage.frame.size.width / 2;
self.userImage.clipsToBounds = true;
For circular imageview, use the below code.
self.imageView.layer.cornerRadius = self.imageView.frame.size.width / 2;
self.imageView.clipsToBounds = true
Don't forget to change the cornerRadius in viewDidLayoutSubviews method of your UIView.
Example:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.imageView.layer.cornerRadius = self.imageView.frame.size.width / 2;
self.imageView.clipsToBounds = true
}
Yes, it is possible to give layer.cornerRadius
(need to add
#import <QuartzCore/QuartzCore.h>
)
for create circular any control but in your case instead of set layer
of UIImageView
it is The
Best Way to Create Your Image as circular and add it on UIImageView
Which have backGroundColor
is ClearColor
.
Also refer this Two Source of code.
https://www.cocoacontrols.com/controls/circleview
and
https://www.cocoacontrols.com/controls/mhlazytableimages
This might be helpful in your case: