简体   繁体   English

具有自定义阴影图像的UIButton

[英]UIButton with custom shadow image

I need to achieve effect of my button like this: 我需要这样实现按钮的效果:

在此处输入图片说明

My questions are: 我的问题是:

  1. How can I add this custom shadow to button, so only 'BUTTON' surface reacts for touches? 如何将自定义阴影添加到按钮,以便只有“按钮”表面会产生触摸反应?
  2. When I have the next button in the bottom, close to previous one, how can I be sure that it will not be covered by upper's button shadow? 当我将下一个按钮放在底部时,与上一个按钮接近时,如何确定上按钮的阴影不会覆盖它? I need to have all the buttons in front and all the shadows in the back. 我需要将所有按钮放在前面,并将所有阴影放在后面。
  1. If you want to add the shadow without having it clickable, you need to add an imageView to as a subview to the button. 如果要添加阴影而不使其可单击,则需要将imageView添加为该按钮的子视图。 (make sure clip subviews is disabled). (确保剪辑子视图已禁用)。

  2. If you want the shadow of one button not appearing on top of the other, then you need to have the shadow(s) added separately to the main parent view. 如果您希望一个按钮的阴影不出现在另一个按钮的顶部,则需要将阴影单独添加到主父视图中。 The solution in option 1 will not work. 选项1中的解决方案将不起作用。 Its not neat, but its the only way i can think off. 它不是整洁的,但是它是我可以考虑的唯一方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM