I am trying to decrease the size of a portion of my string and am using the below code. My output is not correct. I am only seeing my first font attribute being used for the entire string, not the specified range.
NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:title];
NSInteger _stringLength=[descriptionText length];
[attString addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"Gotham-Bold" size:20.0]
range:NSMakeRange(0, 10)];
[attString addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"Helvetica-Bold" size:12.0]
range:NSMakeRange(11, _stringLength-1)];
[self.description setAttributedText:attString];
I've had this issue too. For the second font selection you need to set the minus on the string length to be the same as where it starts.
[attString addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"Helvetica-Bold" size:12.0]
range:NSMakeRange(11, _stringLength-11)];
rather than:
[attString addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"Helvetica-Bold" size:12.0]
range:NSMakeRange(11, _stringLength-1)];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With