我没有太多的运气将垂直居中的标签添加到UINavigationBar
的TitleView上。你可以在下面看到它的样子。在UINavigationBar中垂直居中标签TitleView
这是我如何添加标签:
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = NSLocalizedString(@"activeSessionsTitle",@"");
titleLabel.font = [Util SETTING_NEO_HEADER_FONT];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.shadowColor = [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.25f];
titleLabel.shadowOffset = CGSizeMake(0.0f, -1.0f);
[titleLabel sizeToFit];
super.navigationItem.titleView = titleLabel;
我觉得它为什么这样做的原因是有一些奇怪的与我使用的是实际的字体 - 如我不得不在按钮等内部重新定位。除了导航栏外,我已经能够解决这个问题了。
看到这个职位http://stackoverflow.com/a/8475788/716216 – 2012-03-28 22:08:58