![](/img/trans.png)
[英]UIButton's layer.cornerRadius removes visibility of button title
[英]Button at smaller size not round with layer.cornerRadius
我試圖創建一個按鈕並使用該代碼設置其樣式:
button.tintColor = UIColor.white
button.contentEdgeInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
button.backgroundColor = .clear
button.layer.cornerRadius = 50
button.layer.borderWidth = 2
button.layer.borderColor = UIColor.white.cgColor
我的按鈕大小為100x100,如果我將其縮小(例如,如下所示為80x80),則邊框不再圓了:
如何獲得圓心?
使用下面的代碼
button.layer.cornerRadius = button.frame.size.width/2
確保每次的高度和寬度均相等。
請將角半徑設置為buttonWidth / 2。 我假設您的按鈕具有相等的寬度和高度。
button.layer.cornerRadius = button.frame.size.width/2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.