我正在尝试根据线框创建一个半圆形按钮。
但结果不对。
这是我用 C# 编写的代码:
PORCalculatorButton.Layer.CornerRadius = PORCalculatorButton.Layer.Bounds.Width / 2;
PORCalculatorButton.ClipsToBounds = true;
PORCalculatorButton.Layer.MaskedCorners = (CoreAnimation.CACornerMask)3;
按钮也有布局限制。
谁能告诉我哪里做错了或者是否有更好的方法? 我会接受 ObjC、Swift 或 C# 中的任何答案 谢谢。
最佳答案
试试下面的代码:
let circlePath = UIBezierPath.init(arcCenter:
CGPointMake(PORCalculatorButton.bounds.size.width / 2, PORCalculatorButton.bounds.size.height), radius: PORCalculatorButton.bounds.size.height, startAngle: 0.0, endAngle: CGFloat(M_PI), clockwise: false)
let circleShape = CAShapeLayer()
circleShape.path = circlePath.CGPath
PORCalculatorButton.layer.mask = circleShape
关于ios - 自定义 iOS UIButton 形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52423282/