Airagale
Airagale

Reputation: 225

How to select UIImage in storyboard from View Controller

I am currently trying to select a UIImageView that I have created in the storyboard in my view controller.

Is there a method equivalent to android's findViewbyId in objective c?

Upvotes: 0

Views: 149

Answers (4)

GeneCode
GeneCode

Reputation: 7588

Use the viewWithTag

   UIImageView *yourImage = (UIImageView*)[self.view viewWithTag:20];

Upvotes: 0

Lachlan
Lachlan

Reputation: 312

After creating an IBOutlet as Samantha suggested you will need to add a gesture recogniser to your UIImageView.

I would suggest adding the gesture recognizer in viewDidLoad:

-(void)viewDidLoad {
    [super viewDidLoad];
    UITapGestureRecognizer *singlePress =  [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewPressed)];
    [singleTap setNumberOfTapsRequired:1];
    [_imageView addGestureRecognizer:singleTap];
}

- (void)imageViewPressed {
    //Perform imageView action here
}

Upvotes: 0

Samantha
Samantha

Reputation: 36

Why not just make an IBOutlet for the imageview?

Then you can just access it by something like

self.imageView

Where imageView is what you named your outlet.

Upvotes: 2

Zuzana Paulis
Zuzana Paulis

Reputation: 951

Place a UIButton over your UIImageView.

Upvotes: 0

Related Questions