[英]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?此外,我已经在 IOS 9 和 IOS 10 以及模拟器和设备中尝试过它,那里的任何人都面临同样的问题?
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.这涉及到最后一个问题,当将 Storyboard 用于 tableview 时,如何动态设置标签的角半径。
Try putting this试试把这个
cell.label.layer.masksToBounds = YES;
in awakeFromNib
or init
if you are not using xib or storyboard and put在
awakeFromNib
或init
如果你不使用xib 或storyboard 并把
cell.label.layer.cornerRadius = cell.label.frame.size.width/2;
in layoutSubviews
of your UITableViewCell
.在
UITableViewCell
layoutSubviews
中。
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.