是否有一种直接的方法可以覆盖导航控制器内导航栏中当前导航栏项目的 titleView?我尝试创建一个新的 UIView 并用我自己的 UIVIew 替换 topView 的 titleView 属性,但没有成功。
基本上,我想要一个多行标题作为导航栏标题。有什么建议么?
Set the titleView
的财产UINavigationItem
。例如,在视图控制器的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
它显示如下:
记住titleView
财产是ignored https://stackoverflow.com/questions/9690409/uinavigationitem-titleview-ignored-if-leftbarbuttonitem-is-set if leftBarButtonItem
is not nil
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)