Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Giving UIView rounded corners

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?

like image 209
itsaboutcode Avatar asked Oct 02 '09 13:10

itsaboutcode


People also ask

How do I add inner shadow to UIView with rounded corners?

Add subview with the same color which will be centered on the parent and will be with several pixels smaller. Like this you will have space from each side of the parent. On the parent turn on clipping subviews and add shadow to the inner view. Like this, you can have an inner shadow.

How do you set corner radius for view in 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)

How do you label corner radius in Swift?

"label. layer. masksToBounds = true" is an important code, if you apply corner radius to a label and if it dosen't work than adding this will definitely add the corner radius to a particular label.. So this should be the correct answer..


Video Answer


1 Answers

Try this

#import <QuartzCore/QuartzCore.h> // not necessary for 10 years now  :) 

...

view.layer.cornerRadius = 5; view.layer.masksToBounds = true; 

Note: If you are trying to apply rounded corners to a UIViewController's view, it should not be applied in the view controller's constructor, but rather in -viewDidLoad, after view is actually instantiated.

like image 86
Ed Marty Avatar answered Sep 29 '22 20:09

Ed Marty