Sie sollten eine UILabel
mit einem zugeschrieben Titel als benutzerdefinierte Titelansicht für Ihre Navigationsleiste.
let titleLabel = UILabel()
//attributes for the first part of the string
let firstAttr: [NSAttributedStringKey: Any] = [.font: UIFont.boldSystemFont(ofSize: 16),
.foregroundColor: UIColor.blue]
//attributes for the second part of the string
let secondAttr: [NSAttributedStringKey: Any] = [.font: UIFont.systemFont(ofSize: 16),
.foregroundColor: UIColor.red]
//initializing the attributed string and appending the two parts together
let attrString = NSMutableAttributedString(string: "Navigation", attributes: firstAttr)
let secondAttrString = NSAttributedString(string: " Bar Title", attributes: secondAttr)
attrString.append(secondAttrString)
//setting the attributed string as an attributed text
titleLabel.attributedText = attrString
//finding the bounds of the attributed text and resizing the label accordingly
let maxSize = CGSize(width: CGFloat.greatestFiniteMagnitude, height: .greatestFiniteMagnitude)
titleLabel.frame.size = attrString.boundingRect(with: maxSize, options: .usesLineFragmentOrigin, context: nil).size
//setting the label as the title view of the navigation bar
navigationItem.titleView = titleLabel
Ergebnis:
danke. Ich verstehe es! – usinuniverse