我如何使用“真实图像”制作一个可点击的按钮?
我已经几天没有找到这样的问题了,所以我想我会把它发布在这里......
所以假设我有一张雪花的图片,我通常会拖入一个 uibutton 并设置为自定义并添加图像,但是我不希望这样,因为它会在图像周围形成方形边框,并且我希望按钮本身就是图像。
因此图像的边框将是按钮的最外层部分,仅此而已。
我将如何继续这样做?
I have not found an question like this in a few days so I thought I would post it here...
So say I have a picture of a snowflake, I would usually drag in a uibutton and set to custom and add the image in but I do not want that because it will make a square border around the image and I want the button itself to be the image.
So the border of the image would be the outermost part of the button and nothing more.
How would I go upon doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设图像具有透明背景,可以显示雪花不存在的地方...
您可以将其添加为 UIImageView,将其注册为“内部触摸”操作,然后根据图像检查触摸的 X/Y 坐标图像的 X/Y 坐标。如果它们位于透明位上,则这不是“按钮按下”,但如果有数据,则这是有效的按钮按下。
有几个“颜色选择器”测试代码应用程序可以做类似的事情。您应该能够使用他们的代码作为起点。
Assuming the image has a transparent background which shows through where the snowflake isn't...
You could add it as UIImageView, register it for "touch up inside" actions, then check the X/Y coordinates of the touch up against the the those X/Y coordinates of the image. If they are on a transparent bit, then it's not a "button press", but if there is data, it was a valid button push.
There are several "color picker" test code applications out there which do similar things. You should be able to use their code as a starting point.