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:
Has anyone any idea?Thank you! EDIT:
You should define in your class property:
@property (nonatomic, assign) IBOutlet UINavigationBar *navigationBar;
You should set that class as
File's Owner
.- You should connect your navigation bar with property from 1. (Using IBOutlet)
- 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];
精彩评论