正如您所看到的,导航标题位于两个按钮下方。
两个左/右按钮被添加到导航栏的 subview 。 如何设置导航标题宽度?尽管看起来像...
我的代码如下:
self.navigationItem.titleView.frame=CGRectMake(0, 0, 20, 40);
[[self navigationItem]setTitleView:bigLabel];
最佳答案
如果您的UILable
太长,您可以在iphone`中设置导航栏标题,但在ipad中您可以使用相同的逻辑:-
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
[label setBackgroundColor:[UIColor clearColor]];
[label setNumberOfLines:0];
[label setTextColor:[UIColor whiteColor]];
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont systemFontOfSize:12]];
NSString *str =@"1234567890 1234567890 1234567890 1234567890 1234567890 123456";
[label setText:str];
self.navigationItem.titleView = label;
}
希望它能帮助你..:)
关于iphone - iPhone SDK 中导航标题未正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14050345/