Reputation: 559
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
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