Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Swift中创建不规则的UIButton,其中透明零件不可攻丝_Ios_Swift - Fatal编程技术网

Ios 在Swift中创建不规则的UIButton,其中透明零件不可攻丝

Ios 在Swift中创建不规则的UIButton,其中透明零件不可攻丝,ios,swift,Ios,Swift,我正在制作一个饼图,其中每个扇区都是一个带有背景图像的单独按钮,但UIButton是一个矩形,所有按钮都重叠。有没有办法使UIButton成为不规则图像的精确形状(在Swift中),这样就不会发生这种情况 如有任何帮助,我将不胜感激。就我而言,CAShapeLayer可能是实现饼图的更好方法。通过这样做,您可以使用 [layer hitTest:] 方法来处理触摸操作。您可以使用UIBezierPath或CGPath来定义饼图部分,并使用它们的or来检测触摸您可以在类似[此]的图像中使用UI

我正在制作一个饼图,其中每个扇区都是一个带有背景图像的单独按钮,但UIButton是一个矩形,所有按钮都重叠。有没有办法使UIButton成为不规则图像的精确形状(在Swift中),这样就不会发生这种情况


如有任何帮助,我将不胜感激。

就我而言,
CAShapeLayer
可能是实现饼图的更好方法。通过这样做,您可以使用

[layer hitTest:] 

方法来处理触摸操作。

您可以使用UIBezierPath或CGPath来定义饼图部分,并使用它们的or来检测触摸

您可以在类似[此]的图像中使用
UIApgestureRecognitizer
(,而不是使用UIButton在这种情况下,这可能比在多个UIButton上覆盖
-containsPoint:
-hitTest:
更好。只需将其设置为一个视图,并在该视图上进行数学运算,以对触摸做出适当反应。(只有因为某种原因,你真的需要一个UBIUTUNN的行为/语义,如果你考虑走下那条路)你会如何使用CAShapeLayer的Swift与Swift?