更改navigationItem.title的位置 [英] Change position of navigationItem.title
本文介绍了更改navigationItem.title的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的ViewDidLoad中,我尝试类似的操作,但不起作用:
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 addSubview:label];
我想在我的NavigationBar的左侧显示一个标签.
或者也许更改navigationBar.title的位置
I want to display a label in the left part of my NavigationBar.
Or maybe change the navigationBar.title position
谢谢
推荐答案
您可以使用左侧文本对齐方式将导航项的标题视图设置为UILabel:
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.
这篇关于更改navigationItem.title的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文