1

In the ViewController I would like to:

1) Detect if the UIView has been selected
2) Insert an image at 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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

How do I call a method in the view from the controller? I'm finding it quite hard understanding what to do - it's quite difficult coming from a Java background.
For a button, you really just need to do something like [button setBackgroundImage:myImage forControlState:UIControlStateHighlighted] when you initialize it. The button itself will then automatically handle touch events and highlight appropriately. If you need a method to be called when the user taps the button, you can use addTarget:action:forControlEvents:: developer.apple.com/library/ios/documentation/UIKit/Reference/…
Thanks a lot for that. If I could bother you with just another quick question: How do I create an array that is going to be edited by the controller but the view needs access to it?
That's a complex enough question that you might want to open up a new thread. Without knowing any specifics, one answer is probably that the view shouldn't have access to it, but should use delegation to get the data it needs.
Thanks for your help. In case you want a go at that question: stackoverflow.com/questions/4361989/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.