Skip to content

Commit

Permalink
Merge pull request honcheng#13 from kashifsoofi/master
Browse files Browse the repository at this point in the history
Style text as both bold and italic with <bi>text</bi>
  • Loading branch information
honcheng committed Aug 10, 2012
2 parents 97ace1e + db3aec0 commit fed3859
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 fed3859

Please sign in to comment.