user487588
user487588

Reputation: 740

iPhone, Order UIImages Programmatically

Essentially I would like to add a UIImage programmatically to my interface, using:

[[self view] addSubview: myImage]

However, I would like to add the image BEHIND an existing image already present in the interface builder. Is there a method to accomplish this?

Upvotes: 1

Views: 111

Answers (2)

brain
brain

Reputation: 5546

UIView has a number of methods for inserting subviews into different places.

If you know which subview you want it to go behind you could use:

- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview

Or if you know the index try:

- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index

If you make the existing image an IBOutlet you could use the first method I mentioned.

Upvotes: 1

Vertism
Vertism

Reputation: 165

Use

[[self view] insertSubview:myImage atIndex:i]

i specifies the z index, where a higher index will be above a view with a lower index, so if i = 0 the view will be at the bottom.

Upvotes: 1

Related Questions