My login view has a subview which has a UIActivityView
and a UILabel
saying "Signing In…". This subview has corners which aren't rounded. How can I make them round?
Is there any way to do it inside my xib?
My login view has a subview which has a UIActivityView
and a UILabel
saying "Signing In…". This subview has corners which aren't rounded. How can I make them round?
Is there any way to do it inside my xib?
if round corner not working in viewDidload() it's better to write code in viewDidLayoutSubview()
Hope this helps!
Using UIView Extension:
Usage:
Swift
Short answer:
Supplemental Answer
If you have come to this answer, you have probably already seen enough to solve your problem. I'm adding this answer to give a bit more visual explanation for why things do what they do.
If you start with a regular
UIView
it has square corners.You can give it round corners by changing the
cornerRadius
property of the view'slayer
.Larger radius values give more rounded corners
and smaller values give less rounded corners.
This might be enough to solve your problem right there. However, sometimes a view can have a subview or a sublayer that goes outside of the view's bounds. For example, if I were to add a subview like this
or if I were to add a sublayer like this
Then I would end up with
Now, if I don't want things hanging outside of the bounds, I can do this
or this
which gives this result:
Both
clipsToBounds
andmasksToBounds
are equivalent. It is just that the first is used withUIView
and the second is used withCALayer
.See also
Now you can use a swift category in UIView (code bellow the picture) in with @IBInspectable to show the result at the storyboard (If you are using the category, use only cornerRadius and not layer.cornerRadius as a key path.
set cornerRadious Property for round View
set masksToBounds Boolean Value for image will not still be drawn outside the corner radius boundary