How do I make a UIImageView with rounded corners on a Swift iOS Playground?
Inside it needs to be filled with a color.
I was tired of writing set radius and mask to bound for each UIView. So I made the following extenstion for UIView. Should work for every UIView subclass, though I have not tested it. The extension can be narrowed down for specific Views you use of course.
extension UIView {
func setRadius(radius: CGFloat? = nil) {
self.layer.cornerRadius = radius ?? self.frame.width / 2;
self.layer.masksToBounds = true;
}
}
It will default to the view's half width if you don't pass it any specific value.