如何使一个按钮在Swift中有一个圆形边框?

前端之家收集整理的这篇文章主要介绍了如何使一个按钮在Swift中有一个圆形边框?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用swift在最新版本的Xcode 6中构建一个应用程序,并想知道如何可以修改我的按钮,以便它可以有一个圆形的边框,我可以调整自己,如果需要。一旦这样做,我怎么能改变边框本身的颜色而不添加背景呢?换句话说,我想要一个没有背景的略圆形按钮,只有一个特定颜色的1pt边框。我一直在寻找可能有帮助,但只能找到如何做的Xcode 5和/或使用Objective-C的视频。任何帮助将非常感谢:)提前感谢!
使用button.layer.cornerRadius,button.layer.borderColor和button.layer.borderWidth。
注意,borderColor需要一个CGColor,所以你可以说例如(Swift 2):
button.backgroundColor = UIColor.clearColor()
button.layer.cornerRadius = 5
button.layer.borderWidth = 1
button.layer.borderColor = UIColor.blackColor().CGColor

对于Swift 3:

button.backgroundColor = .clear
button.layer.cornerRadius = 5
button.layer.borderWidth = 1
button.layer.borderColor = UIColor.black.cgColor
原文链接:https://www.f2er.com/swift/321512.html

猜你在找的Swift相关文章