Permalink
Browse files

Merge pull request #13 from kashifsoofi/master

Style text as both bold and italic with <bi>text</bi>
  • Loading branch information...
2 parents 97ace1e + db3aec0 commit fed38597ac850f3ccc40b3044d21bc604210e5af @honcheng honcheng committed Aug 10, 2012
Showing with 13 additions and 0 deletions.
  1. +13 −0 RTLabelProject/Classes/RTLabel.m
@@ -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;
@@ -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)
@@ -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) {

1 comment on commit fed3859

How to display tag "<" and ">",I use your code,but I don't know how to display Character Entities。

Please sign in to comment.