【发布时间】:2015-04-08 11:41:36
【问题描述】:
如何在 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;
【问题讨论】:
-
你能展示一个你想要的图片示例吗?
-
看看OBShapedButton。有了这个,您可以重叠 2 个
UIButtons,让它们看起来像一个按钮,只有当您点击图像上的某个区域时,任何一个按钮才会响应。但是,您需要为按钮自定义图像。
标签: ios uibutton quartz-core