开发者

put title for NavigationBar

开发者 https://www.devze.com 2023-04-06 15:18 出处:网络
I have the following: header file: UINavigationBar *navigationBar; UINavigationItem *navigationItem; implem开发者_高级运维entation file:

I have the following:

header file:

 UINavigationBar *navigationBar;
  UINavigationItem *navigationItem;

implem开发者_高级运维entation file: in viewDidLoad method I tried these:

self.navigationBar.topItem.title = @"title text";

and also this:

  self.navigationItem.title = @"MyTitle";
  [self.navigationBar pushNavigationItem:navigationItem animated:NO];

But no title seems to appear on the black up bar:

put title for NavigationBar

Has anyone any idea?Thank you! EDIT:

put title for NavigationBar


  1. You should define in your class property:

    @property (nonatomic, assign) IBOutlet UINavigationBar *navigationBar;

  2. You should set that class as File's Owner.

  3. You should connect your navigation bar with property from 1. (Using IBOutlet)
  4. Now you can set its title using : self.navigationBar.topItem.title = @"title text";


Try this:-

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
label.font = [UIFont boldSystemFontOfSize:14.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
self.navigationItem.titleView = label;
label.text = [dataItem objectForKey:@"title"];
[label release];
0

精彩评论

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

关注公众号