12

I am using some labels in a view. I want to make rounded corner label in my iphone application. I use following code to do this but it's not work. I got have some errors to use that properties.

label.layer.borderColor = [UIColor blueColor].CGColor;
label.layer.borderWidth = 4.0;
label.layer.cornerRadius = 8;
Cœur
  • 32,421
  • 21
  • 173
  • 232
M.B
  • 875
  • 2
  • 14
  • 30
  • How about putting an rounded corner image as background of the uilabel?? – Yama Puvar Dec 16 '11 at 05:30
  • Possible duplicate of [How do I create a round cornered UILabel on the iPhone?](http://stackoverflow.com/questions/510382/how-do-i-create-a-round-cornered-uilabel-on-the-iphone) – Besi Mar 31 '16 at 21:50

5 Answers5

19

I was facing the same problem, using a UILabel with backgroundColor in a cell, and added this to work correctly :

label.layer.cornerRadius=8.0;
label.clipsToBounds=YES;
Felipe FMMobile
  • 1,631
  • 20
  • 17
13

Just add #import <QuartzCore/QuartzCore.h> in your .m file

and suppose you have a UILabel *myLabel;

just do [myLabel.layer setCornerRadius:20]; //value '20' can be changed according to your wish :)

Ajeet Pratap Maurya
  • 4,224
  • 3
  • 26
  • 44
11

Hard to know for sure what you're asking as you didn't include the errors you're getting. Have you added the QuartzCore framework to your project and #import <QuartzCore/CALayer.h> to the file modifying the layer? If that's not it, add the errors and more info to your question.

EDIT: you can also #import <QuartzCore/QuartzCore.h> as suggested in the comments. QuartzCore.h includes CALayer.h along with the rest of the QuartzCore components.

XJones
  • 21,828
  • 10
  • 63
  • 81
5

This simple code enough for RoundLabel

LabelName.layer.cornerRadius = LableName.frame.size.height/2;
LabelName.layer.masksToBounds = YES;
Ramdhas
  • 1,723
  • 1
  • 17
  • 26
1

I would create a view with rounded corners and add the label to that view.

daihovey
  • 3,653
  • 13
  • 62
  • 103