[英]Button at smaller size not round with layer.cornerRadius
I tried to create a button and style it with that code: 我试图创建一个按钮并使用该代码设置其样式:
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
My button size was 100x100 and if I make it smaller (eg 80x80 as shown below) the border is not round anymore: 我的按钮大小为100x100,如果我将其缩小(例如,如下所示为80x80),则边框不再圆了:
How do I get the centered circle round aswell? 如何获得圆心?
use this below code 使用下面的代码
button.layer.cornerRadius = button.frame.size.width/2
Make sure height and width are equal at every time. 确保每次的高度和宽度均相等。
Kindly set corner radius as buttonWidth/2. 请将角半径设置为buttonWidth / 2。 I assume your button is having equal width and height.
我假设您的按钮具有相等的宽度和高度。
button.layer.cornerRadius = button.frame.size.width/2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.