使用CALayer创建自定义形状按钮 [英] Create Custom shaped button using CALayer

查看:111
本文介绍了使用CALayer创建自定义形状按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实现以下目标的最佳方式是什么?

what is the best way to achieve the following.

基本上我想要做的是创建一个难以处理的区域,用户可以触摸该区域并进行后续操作。例如,在图片中,用户点击绿色区域,弹出窗口带有一些选项。同样地,如果可能的话,在披萨切片中会有不同颜色的难以处理的区域或按钮。

Basically what I want to do is to create an "intractable area" where the user can touch and subsequent actions will take place. For example in the picture the user taps the green area a pop is presented with some options. Similarly there would be different colour "intractable areas or buttons" with in that pizza slice, if you may.

我想通过CALayer创建按钮并尝试适合他们在空状态图像的边界,但我不知道如何实现这一点。任何其他想法都很受欢迎。

I was thinking of having buttons created through CALayer and try to fit them with in the bounds of the empty state image, but i don't know how to achieve this. Any other ideas are well appreciated.

推荐答案

我会继承 UIButton UIControl 来制作自定义按钮。然后覆盖 pointInside:withEvent:以查看触摸事件是否在正确的区域内。

I would subclass UIButton or UIControl to make your custom button. Then override pointInside:withEvent: to see if the touch event is within the correct region.

请参阅以下链接:更多的信息和想法:

See these links for more info and ideas:

  • Non-Rectangular Buttons on iOS
  • Abusing UIView (see section on pointInside:withEvent:)
  • How to create a transparent window with non-rectangular buttons?
  • iPhone button with non-rectangle shape?
  • OBShapedButton

这篇关于使用CALayer创建自定义形状按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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