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.
Asked
Active
Viewed 257 times
-1
-
You need to use an `NSAttributeString` (or probably an `NSMutableAttributedString`). – rmaddy Feb 21 '14 at 05:08
-
Show us some `Code`, what have you tried ? – Janak Nirmal Feb 21 '14 at 05:15
-
possible duplicate of [Any way to bold part of a NSString?](http://stackoverflow.com/questions/6013705/any-way-to-bold-part-of-a-nsstring) – rmaddy Feb 21 '14 at 05:23
2 Answers
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

user3323288
- 34
- 3