Reputation: 690
I have an UIImage
above which I am supposed to add another UIImage
programmatically, above which there will be an UILabel
. I successfully added the Image but it overlaps the Label.
If 1. BG image 2.Image to be added programmatically 3. Label,
then the sequence I want is, 1 2 3
and what I get is
1 3 2
2 overlaps my Label. I have tried Send to Back, Bring to Front and bringSubviewToFront
. It did not work.
Upvotes: 0
Views: 1101
Reputation: 1409
i m not sure,but you try this:
Set the property masksToBounds: YES for the UIImageView.
Upvotes: 0
Reputation: 363
UIImageView *img2=[[UIImageView alloc] initWithImage: [UIImage imageNamed: @"TDK 3 Speaker.png"]];
//img2.backgroundColor=[UIColor clearColor];
[BgImage addSubview:img2];
UILabel *lblText=[[UILabel alloc]initWithFrame:CGRectMake(200, 0, 200, 40)];
lblText.text=@"I am Here";
//lblText.backgroundColor=[UIColor clearColor];
[BgImage addSubview:lblText];
Upvotes: 1
Reputation: 27050
If you want to show BG Image (1) then you can also use UIView
instead of UIImageView
You can also do the samething with UIImageView
as well.
[yourUIView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"yourBackGroundImage"]]];
[yourUIView setFrame:CGRect(x,y,width,height)]; //yourExpectedFrame;
Now, create a UIImageView
(2) with UIImage
and also set a frame
within that UIView
, also create a UILabel
(3) and give it frame
as per the UIView
and accordingly with UIImageView
. That's all. You done!.
Upvotes: 0
Reputation: 20021
The order of adding is important here the later one comes in front Add subview should be called in an order first BGImage then Image and then Label
Upvotes: 0
Reputation: 2807
try this, add QuartzCore.framework and in your header file
#import <QuartzCore/QuartzCore.h>
and in you implementation file
your_Label.layer.zPosition=your_secondImage.layer.zPosition+1;
Upvotes: 0
Reputation: 7226
What you should do is add the particular images in that sequence itself, i.e. in the ViewWillAppear or the ViewDidLoad method use the method
self.view addSubview:BGimage
.
Then add the next image on the previous one like
BGimage addSubview:image2
.
Similarly add the UILabel on the Image 2 like
Image2 addSubview:Label
This will put your images and the label in the particular sequence you want :)
Upvotes: 0