-1

I have a string as "xyz pqr has Invited you to Join The Game under Her group". the substrings which are in bold colour are in between a bracket like in xml. i want to do the same bold functionality in ios.

ADJ
  • 1,531
  • 1
  • 11
  • 15

2 Answers2

1

try this -

NSString *str = @"xyz pqr has Invited you to Join The Game under Her group";
NSRange range1 = [str rangeOfString:@"xyz pqr"];
NSRange range2 = [str rangeOfString:@"The Game"];
NSRange range3 = [str rangeOfString:@"Her"];
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:str];
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys: @"Bold-Font", NSFontAttributeName,nil];
[attributedText setAttributes:attrs range:range1];
[attributedText setAttributes:attrs range:range2];
[attributedText setAttributes:attrs range:range3];

You can set this string to UILabel.

label.attributedText = attributedText;
Rahul Mane
  • 1,005
  • 18
  • 33
-1

You can do this by using attributed string.Download the project of the mentioned link which has a good demo app of Attributed string.

http://www.stanford.edu/class/cs193p/cgi-bin/drupal/node/375