我在导航 Controller 中使用自定义返回按钮:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"Back", nil)
style:UIBarButtonItemStylePlain
target:nil
action:nil];
//and add custom label in this:
heightNav = self.navigationController.navigationBar.frame.size.height;
widthNav = self.navigationController.navigationBar.frame.size.width;
self.aCNavLabel = [[ACNavLabel alloc] initWithFrame:CGRectMake(0, 0, widthNav, heightNav)];
self.aCNavLabel.text = NSLocalizedString(@"Settings", nil);
//
UIView *titleNavView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, widthNav, heightNav)];
self.navigationItem.titleView = titleNavView;
[self.navigationItem.titleView addSubview:self.aCNavLabel];
但是标签没有居中。 请告诉我哪里出错了?
和自定义标签aCNavLabel: @implementation ACNavLabel
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.textColor = [UIColor blackColor];
self.font = FONT_OP_STD(22.0f);
// self.text = title;
self.textAlignment = NSTextAlignmentCenter;
}
return self;
}
我为此更改了一些规则 self.navigationItem.titleView = self.aCNavLabel; 并且有一些不可思议的事情
这是第一个 viewController 和
接下来这是什么???
最佳答案
self.navigationController.navigationBar setTitleTextAttributes:(NSDictionary *)
这个方法就可以了 可以自定义navigationBar标题的字体、颜色、textAlign等属性;
关于ios - 为什么 UINavigation 中的 UILabel 不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20675378/