我在这里有个问题。我想要按钮,以适应背景图像的尺寸完美。
例如:

如您所见,围绕“请求计划”菱形的框与“查看计划”菱形重叠或超过“查看计划”菱形,在运行时,当我单击“查看计划”菱形时,它实际上单击“请求计划”菱形,因为它是重叠的。我有办法解决这个问题吗?
发布于 2017-04-22 04:38:37
您可以创建CustomButton类扩展UIButton,然后重写pointInside
override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
*we need check at this point inside or outside*
return self.alphaAtPoint(point) >= 127
}我们可以通过检查alpha值来检查它
func alphaAtPoint(point: CGPoint) -> CGFloat {
var pixel: [UInt8] = [0, 0, 0, 0]
let colorSpace = CGColorSpaceCreateDeviceRGB();
let alphaInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let context = CGBitmapContextCreate(&pixel, 1, 1, 8, 4, colorSpace, alphaInfo)
CGContextTranslateCTM(context, -point.x, -point.y);
self.layer.renderInContext(context)
return CGFloat(pixel[3])
}发布于 2017-04-21 23:02:21
在故事情节提要中,只要拖动到另一个对象并选择“等宽”和“等长”,您想要等长的东西就可以了。对于重叠,可以更改按钮或视图的顺序,或者重新创建它。
https://stackoverflow.com/questions/43547973
复制相似问题