Corner Radius property of UILabel is not working in iOS 7.1

Surfer picture Surfer · Mar 12, 2014 · Viewed 32.1k times · Source

I am setting the cornerRadius property for UILabel. Its working fine all version of iOS < 7.1. Following code i have used,

UILabel *originaltagLbl = [[UILabel alloc]initWithFrame:CGRectMake(startX, startY, 100,30)];    
[originaltagLbl setFont:[UIFont fontWithName:@"MuseoSans-500" size:15]];
[originaltagLbl setTextAlignment:NSTextAlignmentCenter];
[originaltagLbl setTextColor:UIColorFromRGB(0xffffff)];
originaltagLbl.backgroundColor = [UIColor redColor];
originaltagLbl.layer.cornerRadius = 5;
originaltagLbl.layer.borderColor = [UIColor redColor].CGColor;
originaltagLbl.layer.borderWidth = 1;
[scrollView addSubview:originaltagLbl];

if i use this, just simply displaying the label as rectanglular box, So how to set the corner radius of UILabel in iOS 7.1

Answer

iOS Dev picture iOS Dev · Mar 12, 2014

Add the next line to your code:

originaltagLbl.layer.masksToBounds = YES;

For information see this SO answer, or read documentation.