开发者

Change position of navigationItem.title

开发者 https://www.devze.com 2022-12-24 06:37 出处:网络
In my ViewDidLoad I try something like that but its not working: UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10,2,60,14)];

In my ViewDidLoad I try something like that but its not working:


UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10,2,60,14)];
label.autoresizingMask = UIViewAutoresisingFlecibleWidth;
[self.navigationController.navigationBar addSubv开发者_JAVA技巧iew:label];

I want to display a label in the left part of my NavigationBar. Or maybe change the navigationBar.title position

Thanks,


You can do set navigation item's title view to UILabel with left text alignment:

UILabel* lbNavTitle = [[UILabel alloc] initWithFrame:CGRectMake(0,40,320,40)];
lbNavTitle.textAlignment = UITextAlignmentLeft;
lbNavTitle.text = NSLocalizedString(@"Hello World!",@"");
self.navigationItem.titleView = lbNavTitle;
[lbNavTitle release];

Created this way item's title also tolerates buttons on navigation bar and does not overlap them.

0

精彩评论

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