开发者

Access UIView Methods from Controller / Add UIImage

In the ViewController I would like to:

1) Detect if the UIView has been selected

2) Insert an image 开发者_StackOverflowat the coordinates.

How do I do this? I'm currently using:

CGPoint touchPoint = [touch locationInView:theViewIWant];
UIImage *myImage = [UIImage imageNamed:@"myimage.jpg"];
[myImage drawAtPoint:touchPoint];

But this isn't working.


The most straightforward way to do what you want is to create a UIImageView which you insert or remove as a subview when appropriate.

However, why go to all that trouble when UIButton already provides this functionality? Just create a button of type UIButtonTypeCustom and set a background image only for the "highlighted" state.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜