我使用UINavigationItem的titleView属性来设置一个自定义的UILabel与我所需的字体大小/颜色.这是我的代码:
self.headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0,0.0,400.0,44.0)]; self.headerLabel.textAlignment = UITextAlignmentCenter; self.headerLabel.backgroundColor = [UIColor clearColor]; self.headerLabel.font = [UIFont boldSystemFontOfSize:20.0]; self.headerLabel.textColor = [UIColor colorWithRed:0.259 green:0.280 blue:0.312 alpha:1.0]; self.navigationItem.titleView = self.headerLabel;
在导航栏中,我还有一个左栏按钮.结果是这样的:
解决方法
如果您将headerLabel作为titleView的子视图,则可以设置headerLabel的框架来控制它在titleView内的位置.
你现在的方式,你没有这样的控制.我认为操作系统根据可用空间为您选择titleView的框架.
希望这可以帮助!