iphone – UINavigationItem titleView的位置

我使用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;

在导航栏中,我还有一个左栏按钮.结果是这样的:

alt text http://cl.ly/41164eec656c96e7c913/content

正如你所看到的,文本没有正确的居中.我已经尝试设置标签的x原点,但这没有任何效果.

解决方法

如果您将headerLabel作为titleView的子视图,则可以设置headerLabel的框架来控制它在titleView内的位置.

你现在的方式,你没有这样的控制.我认为操作系统根据可用空间为您选择titleView的框架.

希望这可以帮助!

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...