开发者

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..


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]; 


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

Or use -insertSubview:aboveSubview:.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜