Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an UIImage/-View with rounded corners CGRect (Swift)

How do I make a UIImageView with rounded corners on a Swift iOS Playground?
Inside it needs to be filled with a color.

like image 479
Thomas Avatar asked Aug 24 '14 20:08

Thomas


People also ask

How do I round corners of view in Xcode?

You can give it round corners by changing the cornerRadius property of the view's layer . and smaller values give less rounded corners. Both clipsToBounds and masksToBounds are equivalent.

How do you add corner radius to a storyboard?

Select the view that you want to round and open its Identity Inspector. In the User Defined Runtime Attributes section, add the following two entries: Key Path: layer. cornerRadius , Type: Number, Value: (whatever radius you want)


1 Answers

let imageView = UIImageView(frame: CGRectMake(0, 0, 100, 100)) imageView.backgroundColor = UIColor.redColor() imageView.layer.cornerRadius = 8.0 imageView.clipsToBounds = true 

Result:

enter image description here

like image 126
Mundi Avatar answered Oct 02 '22 19:10

Mundi