Martin
Martin

Reputation: 2863

How to overlap the UIButton and UIImage in a View?

I want to overlap with UIImageView and UIButton like the following picture.

enter image description here

The UIImageView is behind the two UIButton.

If I put the UIImageView behind these two Button , how can I sure the UIButton will not barricaded by the UIImageView ?

Thanks in advance.

Upvotes: 0

Views: 718

Answers (2)

Starscream
Starscream

Reputation: 1138

In order to make sure your buttons are visible and events are caught you can use bringSubviewToFront.

UIImageView *myImageView = //..alloc, init;
UIButton *button1 = //..alloc, init; 
UIButton *button2 = //..alloc, init; 
[self.view addSubview:myImageView];
[self.view addSubview:button1];
[self.view addSubview:button2];
[self.view bringSubviewToFront:button1];
[self.view bringSubviewToFront:button2];

Upvotes: 1

rishi
rishi

Reputation: 11839

You just need to enable the user interaction userInteractionEnabled of UIImageView.

Default value of it is NO, and setting YES will paas down the event to UIButton.

So structure wise on self view you can add image view and on image view buttons can be added.

Upvotes: 0

Related Questions