swift - 找不到UINavigationBar标题文本的numberOfLines属性

时间:2015-08-20 10:30:03

标签: ios swift uinavigationbar

我在swift中使用过UINavigationBar.appearance()。通过使用此功能,我使用以下代码更改了backgroundColortextColor UINavigationBar

但是,我找不到numberOfLines标题文字的UINavigationBar属性。对此有任何帮助表示赞赏。

 var naviAppreance = UINavigationBar.appearance()
 naviAppreance.tintColor = uicolorFromHex(0xffffff)
 naviAppreance.barTintColor = uicolorFromHex(0x00cc66)
 naviAppreance.titleTextAttributes = [ NSForegroundColorAttributeName : UIColor.whiteColor()]

1 个答案:

答案 0 :(得分:2)

您必须设计带有标签的自定义视图,并将其指定为titleView

UINavigationBar

示例Swift代码:

var titleLabel = UILabel(frame: CGRectMake(0, 0, 480, 44))
titleLabel.backgroundColor = UIColor.clearColor()
titleLabel.numberOfLines = 2
titleLabel.shadowColor = UIColor(white: 0.0, alpha: 0.5)
titleLabel.textAlignment = UITextAlignmentCenter
titleLabel.font = UIFont.boldSystemFontOfSize(12.0) 
titleLabel.textColor = UIColor.whiteColor()
titleLabel.text = "This is a\nmultiline string"
self.navigationItem.titleView = label