iPhone中带有偏斜区域的自定义UIButton [英] custom UIButton with skewed area in iPhone
本文介绍了iPhone中带有偏斜区域的自定义UIButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在屏幕上显示带有此图像的按钮.如您在此处看到的,此图像从各个角落都是透明的.
I want to have a button on a screen with this image. this image is transparent from its corners as you can see here.
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(xCo, yCo, kImageSizeWidth, kImageSizeHeight)];
[btn setImage:[UIImage imageNamed:@"aboveImg.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnTapped:) forControlEvents:UIControlEventTouchDown];
但是按钮点击被识别为侧面图像,我不想要这种功能.
But the button tap is recognized out side image and I don't want that kind of functionality.
我的意思是,只有在点击了图片而不是图片以外的内容时,才可以识别该点击.
I mean tap must be recognized only when it is tapped within image not outside image.
那怎么可能?
推荐答案
You can subclass that UIButton, then override its -pointInside:withEvent:
function to something similar to
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event {
if (point is in that rhombus)
return YES;
else
return NO;
}
这篇关于iPhone中带有偏斜区域的自定义UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文