Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel with rounded corner (Xcode 4.5 and iOS 6)

I've just added a UILabel componet into a view and I'm trying to make it a rounded corner UILabel. I’ve been reading some questions and answers related to the same issue but all of them says that I have to change the source code. Is it really necessary in the new Xcode 4.5 and iOS6? Also I’m not sure if I’m able to see the code generated by the mainstoryboard.

Any help will be appreciated.

Many thanks, Marcos

like image 591
vilelam Avatar asked Dec 06 '12 11:12

vilelam


People also ask

How do you round the corners of a label in Swift?

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..

What is corner radius?

The corner radius is a measurement describing the curve on the corners of your labels. This is measured in millimetres and refers to the radius of the circle created if the curve was extended to create a full circle.


2 Answers

You can do it all in Interface Builder.
In XCode, select your .xib file (or your storyboard) to open Interface Builder. Click on your UILabel and open the Identity inspector (if you do not know where it is, go to XCode's Help menu and type in "Identity inspector"). Click the plus button under the User Defined Runtime Attributes pane, and write layer.cornerRadius for the Key Path, chose Number for the Type, and 5 (or any other number) for the Value.
If you run now your project you should get a round-cornered UILabel.

like image 58
RoberRM Avatar answered Nov 26 '22 11:11

RoberRM


to make UILabel with rounded corners do the following:

#import <QuartzCore/QuartzCore.h>

then you should refer to your UILabel

yourLabel.layer.cornerRadius = 5;

5 is just an example, of course

like image 28
Andrey Chernukha Avatar answered Nov 26 '22 11:11

Andrey Chernukha