Skip to content
Browse files

Bold and Italic style for text

New tag and function added to style the text as bold and italic
  • Loading branch information...
1 parent 97ace1e commit db3aec0bb7a9b689f9b5d6df2e3102e6c64b2f4c @kashifsoofi kashifsoofi committed Aug 8, 2012
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) {

0 comments on commit db3aec0

Please sign in to comment.
Something went wrong with that request. Please try again.