自定义UIButton,iPhone中有偏斜区域

时间:2010-05-27 06:31:20

标签: iphone objective-c xcode uiimage uibutton

http://img16.imageshack.us/img16/225/ladibig.png http://img16.imageshack.us/img16/225/ladibig.png

我希望屏幕上有一个带有此图像的按钮。如你所见,这个图像从角落是透明的。

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];

但按钮水龙头可识别出侧面图像,我不想要那种功能。

我的意思是,只有在图像中轻拍而不是在图像外部时才能识别拍子。

这怎么可能?

1 个答案:

答案 0 :(得分:1)

您可以继承该UIButton,然后将其-pointInside:withEvent: function覆盖为类似于

的内容
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event {
   if (point is in that rhombus)
     return YES;
   else
     return NO;
}