我无法设置以编程方式分配UILabel
以在我的 NavigationItem 的 titleView 中居中。我什至将 NSAlignment 设置为 NSAlignmentCenter。这是它的样子:
如您所见..我没有使用正确的 UIBarButtonItem ,但这不应该使文本保持居中吗?这是代码,在viewDidLoad
:
//Set the title of navBar----------
UILabel *navTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 40)]; //0 0 320 10
navTitleLabel.backgroundColor = [UIColor clearColor];
navTitleLabel.textAlignment = NSTextAlignmentCenter;
navTitleLabel.textColor=[UIColor whiteColor];
navTitleLabel.text = @"IMG";
[navTitleLabel setFont: [UIFont fontWithName:@"BullettoKilla" size:16]];
self.navigationItem.titleView = navTitleLabel;
我究竟做错了什么?