开发者

How to create "hotspots" that can be clicked and fire off events on a UIImageView in Xcode

I have a custom graphic that I am 开发者_JAVA百科using as the background to a UIView. On this image there are some text that I would like to create clickable hotspots around. For instance, one says "Next" and one says "Previous", I'd like these to be clickable hotspots that I can capture the event and change a UITextView with some data. So far I have been unable to find any help on defining clickable regions on a UIImageView. Thanks for the help!


I would just create invisible UIButtons that overlay the area you want to be clickable. In Interface Builder, just create the button and set its type to custom and don't provide any text or images. In code:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(120,30,44,44);
[self.view addSubview:button];  //Here you could add it to the UIImageView instead if you wanted to.  Just make sure interaction is not disabled on the image view
button.tag = 1;
[button addTarget:self action:@selector(clickedHotspot:) forControlEvents:UIControlEventTouchUpInside];

Then use the button's tag to determine which button was clicked inside of clickedHotspot:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜