I would like to add some rounded corners to the UIImageView in my project. I wrote following code to implement this but this is not working for me.
Any suggestion ?
btnProfilePic.layer.cornerRadius = 50;
I would like to add some rounded corners to the UIImageView in my project. I wrote following code to implement this but this is not working for me.
Any suggestion ?
btnProfilePic.layer.cornerRadius = 50;
You need to set masksToBounds
to true
self.imageview.layer.cornerRadius = 50;
self.imageview.layer.masksToBounds = true;
setMasksToBound to yes if your UIImageView..
[imgView1.layer setCornerRadius:50];
[imgView1.layer setMasksToBounds:YES];
btnProfilePic.layer.cornerRadius = btnProfilePic.frame.size.height/2;
btnProfilePic.layer.masksToBounds = YES;
And for improving performance you can choose to set
btnProfilePic.layer.shouldRasterize = YES;
Note: For view you are going to round its height and width must be same.
All solutions with layer is very good, and work very clear. The solutions with layer are very expensive for the performance of animation, but very cheap for implementation.
You can use other solution (I use it because have very many small imageViews in a list with scrolling). You can prepare image with rounded corners (and borders if need it) for display it in the imageView. Set backgroundColor for the imageView as clear or same with a parent view and set prepared image to the imageView.
To resize images I use this library to add rounded corners I've wrote custom method (it builds rounded corners path to use it for clip image), for cache resized images I use SDWebImageCache. All operations I run at a background queue. It solution more complex, but you can use it if you have many images and you need best performance for scrolling animation.