具有自定义形状的iOS UIButton



如何在iOS中使用自定义形状创建2个按钮。我需要画两个按钮,像矩形的对角线。左侧是一个按钮,右侧是另一个按钮。我试过使用贝塞尔路径,但如何使其适用于所有设备?

这是我为一键尝试的代码

 UIBezierPath*  bezierPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 138, 118)];
[UIColor.blackColor setStroke];
bezierPath.lineWidth = 20;
[bezierPath stroke];

CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = self.Btn.bounds;
shapeLayer.path = bezierPath.CGPath;
shapeLayer.fillColor = [UIColor clearColor].CGColor;
shapeLayer.strokeColor = [UIColor blackColor].CGColor;
shapeLayer.lineWidth = 120;
self.Btn.layer.mask = shapeLayer;

你不能只做一个按钮,

对其进行子类化并点击CGPoint以确定应设置突出显示/选定等形状

最新更新