开发者

Add a label to UINavigationBar in addition to the titleView

开发者 https://www.devze.com 2023-02-21 20:44 出处:网络
I\'m using a UINavigationController to push my views. I want to add a UILabel above the title in the UINavigationBar of the root view controller.

I'm using a UINavigationController to push my views. I want to add a UILabel above the title in the UINavigationBar of the root view controller.

When I use the following code, the label appears, but under the UINavigationBar:

[self.view addSubview:newLabel];

Is there a way to add the label to the UINavigationBar or to the UIView so that it appears above the navigation bar?

I kn开发者_运维问答ow I can create a new UINavigationBar and build it with multiple controls like this:

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
navBar.barStyle = UIBarStyleBlack; 
navBar.translucent = YES;
[self.view addSubview:navBar];
[navBar release];

UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(20,8,280,30)];
navLabel.text = @"My Text";
[navBar addSubview:navLabel];
[navLabel release];

However, doesn't that defeat the purpose of using the navigation controller?


You can refer this site, may be it help you in sorting your problem

http://iphonesdevsdk.blogspot.com/2011/04/uinavigationbar.html

0

精彩评论

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