First I am formatting the whole Label:
let page3View = UIView(frame: CGRect(x: 0, y: self.view.bounds.height*2, width: self.view.bounds.width, height: self.view.bounds.height))
scrollView.addSubview(page3View)
label3.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width - 40, height: 400)
label3.colorString(text: "Für das erste Beispiel nutzen wir die Zahl 13.",
coloredText: "13")
label3.center = self.view.center
label3.font = UIFont.systemFont(ofSize: 34, weight: .semibold)
label3.numberOfLines = 4
label3.textAlignment = .center
page3View.addSubview(label3)
For the red "13" I am using the following extension:
extension UILabel {
func colorString(text: String?, coloredText: String?, color: UIColor? = .red) {
let attributedString = NSMutableAttributedString(string: text!)
let range = (text! as NSString).range(of: coloredText!)
attributedString.setAttributes([NSAttributedString.Key.foregroundColor: color!],
range: range)
self.attributedText = attributedString
}}
But now I want that the "13" is in the "Snell Roundhand Bold" Font.
It should look like: