如何制作圆形椭圆形按钮?

时间:2016-10-21 21:03:37

标签: ios swift button rounded-corners

我的目标是让我的按钮看起来像这样:

enter image description here

减去按钮周围的黑边。

在阅读了不少帖子之后,我看到大多数解决方案都说要使用

layer.cornerRadius = 10.0

当我这样做时,我得到了这个:

enter image description here

它绕过边缘,但没有给我我想要的目标。

有什么建议吗?

2 个答案:

答案 0 :(得分:10)

Swift 3

myButton.layer.cornerRadius = myButton.frame.height / 2

myButton.backgroundColor = UIColor.blue
myButton.clipsToBounds = true
myButton.tintColor = UIColor.white
myButton.setTitle("Connect With Facebook", for: .normal)

enter image description here

答案 1 :(得分:1)

你可以这样做(例如,如果按钮被称为按钮):

button.layer.cornerRadius = button.bounds.size.height / 2.0
相关问题