4

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

Yury Imashev
  • 2,068
  • 1
  • 18
  • 32
Amdx Rux
  • 95
  • 8

2 Answers2

2

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

Yury Imashev
  • 2,068
  • 1
  • 18
  • 32
  • Ok I think this problem probably exist because I use ActiveLabel pod to achive active links because with normal UILabel it works. Thanks ! – Amdx Rux Sep 23 '18 at 12:07
1

There is a easy way for Objective-C

NSMutableAttributedString *yourAttributedString = [[NSMutableAttributedString alloc] initWithString:@"Your string text"];

[yourAttributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Proxima Nova" size:18.0f] range:NSMakeRange(0,16)];

range should be length of your string

yasin89
  • 103
  • 8