Take the 2-minute tour ×

I have an NSString, that contains tags [strong][\strong]. Inside this tags, this words must be bold to be shown in a UITextView and then delete all the container tags once words are formatted,and I can't use an UIWebView. I think I must use attributedStrings, but I'm not sure how can I achieve it.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Instead of using UITextView you can use advanced UILabel like OHAttributedLabel or CoreTextAttributedLabel. Download the sample, its good & clean. You can change colors, fonts, sizes, underline, and almost everything for parts of a string.

share|improve this answer
Many thanks!!. OHAttributedLabel seems to be the solution, but it is a hell to include in my project. Now that I have achieved it, OHASTagParserBasicMarkup class is not available for me to parse html tags. I don't know why.... –  roof Oct 16 '12 at 10:12
add comment

For iOS 6.0

Attributed strings will help you!

NSString* string = @"[strong]yourString[/strong]";
string = [string stringByReplacingOccurrencesOfString:@"[strong]" withString:@""]
string = [string stringByReplacingOccurrencesOfString:@"[\strong]" withString:@""];
UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:30.0f];
NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:string];
[attrString addAttribute:NSFontAttributeName value:fontName range:NSMakeRange(0, _stringLength)];

Make sure to set the label text to attributed.

Hope this helps!

share|improve this answer
Thanks for the edit Hemang, kinda new to Stackoverflow :) –  Lofens Oct 16 '12 at 7:56
add comment
if([[yourString substringToIndex:8] isEqual:@"[strong]")
NSString *newString = [yourString substringFromIndex:8];
NSString *newerString = [newString substringToIndex:[newString length]-9];

//Insert to label and change label format to bold.

share|improve this answer
add comment

Your Answer


