Surfer Surfer - 3 months ago 39
Objective-C Question

Corner Radius property of UILabel is not working in iOS 7.1

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

Add the next line to your code:

originaltagLbl.layer.masksToBounds = YES;

For information see this SO answer, or read documentation.

Comments