vinay
vinay

Reputation: 361

Corner Radius for a Label on UItableviewCell is not applying in xcode 8

Here is my code

[cell.label.layer setCornerRadius:cell.label.frame.size.width/2];

here is what I tried :-

cell.label.clipsToBounds = YES;

also tried :-

cell.label.layer.masksToBounds = YES;

also I have Imported:-

#import <QuartzCore/QuartzCore.h>

none of these approaches works.

Also I have tried it in both IOS 9 and IOS 10 and in Simulator as well as device, anyone there who is facing the same Issue?

Answer

Well After some trial and error Methods I found that passing absolute value to the corner radius parameter worked.

[cell.label.layer setCornerRadius:20.0];

which comes to the last question how can you set corner radius for label dynamically when using Storyboard for tableview.

Upvotes: 2

Views: 2256

Answers (1)

nishith Singh
nishith Singh

Reputation: 2998

Try putting this

cell.label.layer.masksToBounds = YES;

in awakeFromNib or init if you are not using xib or storyboard and put

cell.label.layer.cornerRadius = cell.label.frame.size.width/2;

in layoutSubviews of your UITableViewCell.

Hope this helps.

Upvotes: 5

Related Questions