How do I make a UIImageView with rounded corners on a Swift iOS Playground?
Inside it needs to be filled with a color.
Setting layer.cornerRadius = 10 at User Defined Runtime Attributes section on the Identity inspector works even on repeatable elements like table cells.
If you want to have an option to round each UIImageView, you can copy this code into your project without forgetting to check clip to bounds and set its value to true
import UIKit
@IBDesignable
extension UIImageView
{
private struct AssociatedKey
{
static var rounded = "UIImageView.rounded"
}
@IBInspectable var rounded: Bool
{
get
{
if let rounded = objc_getAssociatedObject(self, &AssociatedKey.rounded) as? Bool
{
return rounded
}
else
{
return false
}
}
set
{
objc_setAssociatedObject(self, &AssociatedKey.rounded, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
layer.cornerRadius = CGFloat(newValue ? 1.0 : 0.0)*min(bounds.width, bounds.height)/2
}
}
}
