在Swift中创建一个不规则的UIButton,其中透明部分是不可点击的 [英] Creating an irregular UIButton in Swift where transparent parts are not tappable

查看:361
本文介绍了在Swift中创建一个不规则的UIButton,其中透明部分是不可点击的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am making a pie chart where each sector is a separate button with a background image, but UIButton has a rectangular shape and all the buttons overlap. Is there a way to make a UIButton the exact shape of an irregular image (in Swift) so this does not happen?

任何帮助都将不胜感激

推荐答案

您可以使用UIBezierPath或CGPath来定义饼图部分并使用他们的 containsPoint: CGPathContainsPoint 来检测触摸

You can use UIBezierPath or CGPath to define your pie chart sections and use their containsPoint: or CGPathContainsPoint to detect touch

这篇关于在Swift中创建一个不规则的UIButton,其中透明部分是不可点击的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆