我试图创建一个按钮,并使用该代码设置其样式:
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
每次确保高度和宽度相等。
关于ios - 较小尺寸的按钮不具有layer.cornerRadius圆形,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44157844/