Swift中具有半圆形状的按钮扩展
请在下面的链接下载代码
https://www.dropbox.com/s/noh7ilddkacg67n/test.zip?dl=0
扩展UIButton
{
func mybg(_bg:UIColor){
让circlePath = UIBezierPath.init(arcCenter:CGPoint(x:self.bounds.size.width / 2,y:self.bounds.size.height / 2),
半径:50.0,startAngle:(CGFloat(M_PI / 4)),endAngle:(CGFloat(M_PI)),顺时针:true)
让circleShape = CAShapeLayer()
circleShape.path = circlePath.cgPath
self.layer.mask = circleShape
self.backgroundColor = .red
}
}
用它
导入UIKit
类ViewController:UIViewController {
@IBOutlet弱var CircularButton:UIButton吗?
覆盖func viewDidLoad(){
super.viewDidLoad()
CircularButton?.mybg(_bg:.red)
//加载视图后进行其他任何设置,通常是从笔尖进行。
}
覆盖func didReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
//处理所有可以重新创建的资源。
}
}