uinavigationcontroller - UINavigationBar多行标题

标签 uinavigationcontroller uilabel uinavigationbar title uinavigationitem

是否有一种直接的方法可以覆盖导航 Controller 内导航栏中当前导航栏项目的 titleView?我尝试创建一个新的 UIView 并用我自己的 UIVIew 替换 topView 的 titleView 属性,但没有成功。

基本上,我想要一个多行标题作为导航栏标题。有什么建议吗?

最佳答案

设置UINavigationItemtitleView 属性。例如,在 View Controller 的 viewDidLoad 方法中,您可以执行以下操作:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)];
label.backgroundColor = [UIColor clearColor];
label.numberOfLines = 2;
label.font = [UIFont boldSystemFontOfSize: 14.0f];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = @"This is a\nmultiline string";

self.navigationItem.titleView = label;

#if !__has_feature(objc_arc)
[label release];
#endif

它显示如下:

multi-line titlebar label

记住titleView属性是ignored如果 leftBarButtonItem 不是 nil

关于uinavigationcontroller - UINavigationBar多行标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2422383/

相关文章:

iphone - 在 UILabel 中追加字符串?

ios - iOS 7 中 UINavigationbar 下面的 UISegmentedControl

ios - 将褪色的深色背景设置为 UINavigationBar

ios - UINavigationBar titleView 比栏本高度

ios - childByAppendingPath 由于嵌入导航 Controller 而导致 Segues

swift - 当用户返回上一页时如何隐藏导航栏阴影(快速)

ios - 后退后导航栏与图像重叠

iOS 通用应用程序似乎在手机上略微放大

url - 使用 Monotouch 在 UILabel 中显示可点击链接的最佳方法

iphone - 为什么我的文字在我的 ios 应用程序中看起来如此糟糕?