如何在SWift iOS8中调整或自定义IBOutlet按钮的形状作为内部按钮的图像 [英] How to adapt or custom the shape of a IBOutlet button as the inner button's image in Swift iOS8

查看:125
本文介绍了如何在SWift iOS8中调整或自定义IBOutlet按钮的形状作为内部按钮的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从界面生成器拖动的IBOutlet按钮(在自动布局中更容易使用它)

I have an IBOutlet button dragged from Interface Builder (it's easier to play with it in auto layout )

我在代码中将其旋转了45° href =https://stackoverflow.com/questions/30555787/swift-rotate-oblique-a-button-in-ios8>这里

I rotated it by 45° in code as learned here

var transform = CGAffineTransformMakeTranslation(0.5, 0.5)
var angle = CGFloat(M_PI / 3.9) // degress rotation 3.9
transform = CGAffineTransformRotate(transform, angle)
button.transform = transform
button.layer.rasterizationScale = UIScreen.mainScreen().scale
button.layer.shouldRasterize = true
button.setNeedsDisplay()

现在,我有钻石,三角形,矩形图像放入尽可能多的IBOutlets。这个IBOutlets必须并排。但是按钮的余量我不知道如何切断。

now, I have diamond, triangle, rectangle shaped images to put inside as many IBOutlets. this IBOutlets are required to be side by side. But there are margins of the button that I don't know how to cut off.

所以,紫色是好的,黄色是坏的。紫色区域将是按钮图像但我需要切断黄色边缘区域(现在设置清晰的颜色,但无论如何都是可点击的,我不希望它是这样)

so, purple is good, yellow is bad. purple area will be "the button" image but I need to cut off the yellow margins area (now is set clear color, but is clickable anyway, and I don't want it to be)

我需要在iPhone上制作一个由多种形状制作的UI,每个形状都将并排放在另一个上面,我不希望按钮的不需要区域覆盖下一半的按钮它。任何帮助?

I need to make a UI on iPhone made by many shapes, each of them will be side by side the other, and I don't want the unwanted area of the button to "cover" half the button next to it. any help?

提前感谢

推荐答案

按钮点击是基于的在一个矩形,非旋转的区域。你不能使按钮的可点击区域变成不规则的形状,并且不能与边界矩形重叠。

Button tapping is based on a rectangular, non-rotated area. You can't make a button's tappable area an irregular shape, and can't overlap the bounds rectangles.

你可以旋转包含所有你的所有超视图的坐标系按钮,使它们都倾斜45度。这样你可以有方形按钮的行和列,看起来像钻石,并确实响应每个区域的水龙头。

You COULD rotate the coordinate system of the superview that contains all your buttons, so that they all were tilted 45 degrees. That way you could have rows and columns of square buttons that LOOK like diamonds, and did respond to taps in each region.

您还可以创建一个管理的自定义视图类一个不规则形状的物体网格,像按钮一样,并根据它们包含的图像的不透明部分检测水龙头,但这将是相当多的工作,并涉及一些超出SO帖子范围的相当先进的技术解释。

You could also create a custom view class that manages a grid of irregularly shaped objects that ACT like buttons, and detect taps based on the opaque parts of the images they contain, but that would be quite a bit of work, and involve some fairly advanced techniques that are beyond the scope of a SO post to explain.

这篇关于如何在SWift iOS8中调整或自定义IBOutlet按钮的形状作为内部按钮的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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