Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Style text as both bold and italic with <bi>text</bi> #13

Merged
merged 1 commit into from

2 participants

@kashifsoofi

New tag and function added to style the text both as bold and italic

@kashifsoofi kashifsoofi Bold and Italic style for text
New tag and function added to style the text as bold and italic
db3aec0
@honcheng honcheng merged commit fed3859 into honcheng:master
@honcheng
Owner

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 8, 2012
  1. @kashifsoofi

    Bold and Italic style for text

    kashifsoofi authored
    New tag and function added to style the text as bold and italic
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 0 deletions.
  1. +13 −0 RTLabelProject/Classes/RTLabel.m
View
13 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) {
Something went wrong with that request. Please try again.