我正在使用UINavigationItem的titleView屬性來設置具有所需字體大小/顏色的自定義UILabel。這是我的代碼:UINavigationItem titleView位置
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原點,但這沒有效果。
我看不到圖片... – turingtested 2016-12-13 15:35:49