akshay
akshay

Reputation: 13

how to add a label over an image?

the view generates an image at runtime. i didnt use the iB to create it. when i try a place a label over it ,The label contents dont show up.. here's my code

- (void)viewWillAppear:(BOOL)animated {
    UILabel *Label=[[UILabel alloc]initWithFrame:CGRectMake(0.0, 50.0, 150.0, 20.0)];

    Label.font=[UIFont fontWithName:@"Helvetica"  size:15];
    Label.text=@"sdvdssdvsdv";
    [self.view addSubview:Label];


    UIImageView *Headbar=[[UIImageView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 80.0)];
    Headbar.image=[UIImage imageNamed:@"header.jpg"];
    Headbar.opaque=YES;
    self.header=Headbar;    
    [Headbar release];
    [self.view addSubview:header]; 

    [super viewWillAppear:animated];
}

when i change the frame to CGRectMake(0.0, 80.0, 150.0, 20.0) it shows up.. but i need it on the image.. please help me out..

Upvotes: 1

Views: 2122

Answers (3)

Hoang Pham
Hoang Pham

Reputation: 6949

Try to use the following two functions over the self.view:

- (void)bringSubviewToFront:(UIView *)view
- (void)sendSubviewToBack:(UIView *)view

Edited

It seems to me that you are trying to create a custom navigation with the image as a background and the label on top.

This is not the good way to get your thing done. I suggest you to ask a new question if this is what you want.

Upvotes: 1

kennytm
kennytm

Reputation: 523254

Switch the order to -addSubview: the two UI elements. The view added the last will be shown on the top.

Or use -insertSubview:aboveSubview:.

Upvotes: 2

acheo
acheo

Reputation: 3126

looks like you're adding header after the label so it's covering it up. try changing the order.

move

[self.view addSubview:Label];

so it is after

[self.view addSubview:header]; 

Upvotes: 2

Related Questions