【问题标题】:iOS UIButton with custom shapes具有自定义形状的 iOS UIButton
【发布时间】: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


【解决方案1】:

你不能只做一个按钮,

对它进行子类化并测试 CGPoint 以确定您应该设置突出显示/选定/等的形状

【讨论】:

    猜你喜欢
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多