0

I to display long text with too much modification.. Large text contains special characters. Whenever special character occur below line should be bold and on occur of \n new label should generated.

Urvish Modi
  • 1,118
  • 10
  • 11
  • 2
    Use NSAttributedString : [http://stackoverflow.com/questions/3482346/how-do-you-use-nsattributedstring](http://stackoverflow.com/questions/3482346/how-do-you-use-nsattributedstring) – Karan Dua Feb 18 '16 at 05:40
  • We can't concate normal string with attributed string.. i need som text of string to be boldedand this solution i alredy tried.. Not work – Urvish Modi Feb 19 '16 at 05:35

1 Answers1

2

Try This : you can add any font style in value parameter.Using this you can add style to substring to make it different from normal string.

NSString *strFirst = @"Anylengthtext";
NSString *strSecond = @"Anylengthtext";
NSString *strThird = @"Anylengthtext";

NSString *strComplete = [NSString stringWithFormat:@"%@ %@ %@",strFirst,strSecond,strThird];

NSMutableAttributedString *attributedString =[[NSMutableAttributedString alloc] initWithString:strComplete];

[attributedString addAttribute:NSForegroundColorAttributeName
              value:[UIColor whiteColor]
              range:[strComplete rangeOfString:strFirst]];

[attributedString addAttribute:NSForegroundColorAttributeName
              value:[UIFont fontWithName:@"Roboto-Regular" size:12]
              range:[strComplete rangeOfString:strSecond]];

[attributedString addAttribute:NSForegroundColorAttributeName
              value:[UIColor blueColor]
              range:[strComplete rangeOfString:strThird]];


self.lblName.attributedText = attributedString;
Karan Dua
  • 2,401
  • 3
  • 15
  • 17