aLFaRSi
aLFaRSi

Reputation: 559

setting imageview order on screen

when i create an imageview within the xcode using this code :

UIImageView *img = [[UIImageView alloc] initWithImage:@"image.png"];

img.frame = CGRectMake(40, 40, 80, 80);
img.alpha = 0.25;
[self.view addSubview:img];

it will generate the image in the view, but what if i have like lets say 5 buttons on the screen that i added using IB and i want the image that i created in the xcode to be behind the buttons what should i do ?

is there a line of code to set the image to the back ?

thanks in advance :)

Upvotes: 0

Views: 68

Answers (2)

Mick MacCallum
Mick MacCallum

Reputation: 130193

As stated by @Noah you can use:

[self.view sendSubviewToBack:img];

to simply send your view to the back. You can also use the following for more advanced configurations.

[self.view insertSubview:img aboveSubview:otherSubView];
[self.view insertSubview:img belowSubview:otherSubView];
[self.view insertSubview:img atIndex:MYINDEXPATH];
[self.view exchangeSubviewAtIndex:MYINDEXPATH withSubviewAtIndex:ANOTHERINDEXPATH];

Details can be found in the UIView Class Reference.

Upvotes: 1

Noah Witherspoon
Noah Witherspoon

Reputation: 57149

[self.view sendSubviewToBack:img];

Upvotes: 2

Related Questions