我正在尝试使用 Swift在iOS 11中使用新的大型标题系统.当标题太长时(参见图片示例),它会添加…而不是换行或缩小文本大小.如何添加换行符? 以下是我用来设置标题的一些代码: self.
以下是我用来设置标题的一些代码:
self.navigationController?.navigationBar.prefersLargeTitles = true self.navigationController?.navigationBar.largeTitleTextAttributes = [NSForegroundColorAttributeName: MyGlobalVariable.themeMainColor] self.navigationController?.navigationBar.largeTitleTextAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 22)] navigationItem.title = "Search by Name"试试这个:
for navItem in (self.navigationController?.navigationBar.subviews)! { for itemSubView in navItem.subviews { if let largeLabel = itemSubView as? UILabel { largeLabel.text = self.title largeLabel.numberOfLines = 0 largeLabel.lineBreakMode = .byWordWrapping } } }
它对我有用.