[英]Corner Radius for a Label on UItableviewCell is not applying in xcode 8
這是我的代碼
[cell.label.layer setCornerRadius:cell.label.frame.size.width/2];
這是我嘗試過的:-
cell.label.clipsToBounds = YES;
也試過:-
cell.label.layer.masksToBounds = YES;
我也進口了:-
#import <QuartzCore/QuartzCore.h>
這些方法都不起作用。
此外,我已經在 IOS 9 和 IOS 10 以及模擬器和設備中嘗試過它,那里的任何人都面臨同樣的問題?
回答
經過一些試驗和錯誤方法后,我發現將絕對值傳遞給拐角半徑參數是有效的。
[cell.label.layer setCornerRadius:20.0];
這涉及到最后一個問題,當將 Storyboard 用於 tableview 時,如何動態設置標簽的角半徑。
試試把這個
cell.label.layer.masksToBounds = YES;
在awakeFromNib
或init
如果你不使用xib 或storyboard 並把
cell.label.layer.cornerRadius = cell.label.frame.size.width/2;
在UITableViewCell
layoutSubviews
中。
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.