iosswiftnsattributedstringnsmutableattributedstring

NSMutableAttributedString with different fonts


I have a problem with the combination of two strings:

let finalMutableString = NSMutableAttributedString()
let attributedDot = NSAttributedString(string: " ●", attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 7)])
let firstPartString = NSAttributedString(string: "Sample text", attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 17)])
finalMutableString.append(attributedDot)
finalMutableString.append(firstPartString)
label.attributedText = finalMutableString

And whole text has font size 7.0 not only attributedDot. Why is this how it behaves? Text's should have different sizes


Solution

  • I guess that your code work, but you think that it doesn't because font sizes look pretty much equally.

    Here is what I see with your code

    enter image description here

    And that's what I see when I change size to 2 and 37

    enter image description here

    And that's your original sizes (7 and 17), but for both strings, I've set the same text.

    enter image description here