Skip to content

Commit

Permalink
Bold and Italic style for text
Browse files Browse the repository at this point in the history
New tag and function added to style the text as bold and italic
  • Loading branch information
kashifsoofi committed Aug 8, 2012
1 parent 97ace1e commit db3aec0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions RTLabelProject/Classes/RTLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ - (void)extractTextStyle:(NSString*)text;

- (void)applyItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyBoldStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyBoldItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyColor:(NSString*)value toText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applySingleUnderlineText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyDoubleUnderlineText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
Expand Down Expand Up @@ -285,6 +286,10 @@ - (void)render
// make font bold
[self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
}
else if ([component.tagLabel isEqualToString:@"bi"])
{
[self applyBoldItalicStyleToText:attrString atPosition:component.position withLength:[component.text length]];
}
else if ([component.tagLabel isEqualToString:@"a"])
{
if (currentSelectedButtonComponentIndex==index)
Expand Down Expand Up @@ -670,6 +675,14 @@ - (void)applyBoldStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)
CFRelease(boldFont);
}

- (void)applyBoldItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length
{
NSString *fontName = [NSString stringWithFormat:@"%@-BoldOblique", self.font.fontName];
CTFontRef refFont = CTFontCreateWithName ((CFStringRef)fontName, [self.font pointSize], NULL);
CFAttributedStringSetAttribute(text, CFRangeMake(position, length), kCTFontAttributeName, refFont);
CFRelease(refFont);
}

- (void)applyColor:(NSString*)value toText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length
{
if ([value rangeOfString:@"#"].location == 0) {
Expand Down

0 comments on commit db3aec0

Please sign in to comment.