swift - 找不到 UINavigationBar 标题文本的 numberOfLines 属性
swift - Can't find the numberOfLines attribute of UINavigationBar title text
我在swift中使用了UINavigationBar.appearance()
。通过使用它,我使用下面的代码更改了 backgroundColor
和 UINavigationBar
的 textColor
。
但是,我找不到 UINavigationBar
标题文本的 numberOfLines
属性。对此的任何帮助表示赞赏。
var naviAppreance = UINavigationBar.appearance()
naviAppreance.tintColor = uicolorFromHex(0xffffff)
naviAppreance.barTintColor = uicolorFromHex(0x00cc66)
naviAppreance.titleTextAttributes = [ NSForegroundColorAttributeName : UIColor.whiteColor()]
您必须设计一个带有标签的自定义视图并将其指定为 UINavigationBar
的 titleView
示例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
我在swift中使用了UINavigationBar.appearance()
。通过使用它,我使用下面的代码更改了 backgroundColor
和 UINavigationBar
的 textColor
。
但是,我找不到 UINavigationBar
标题文本的 numberOfLines
属性。对此的任何帮助表示赞赏。
var naviAppreance = UINavigationBar.appearance()
naviAppreance.tintColor = uicolorFromHex(0xffffff)
naviAppreance.barTintColor = uicolorFromHex(0x00cc66)
naviAppreance.titleTextAttributes = [ NSForegroundColorAttributeName : UIColor.whiteColor()]
您必须设计一个带有标签的自定义视图并将其指定为 UINavigationBar
titleView
示例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