Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Created December 22, 2011 22:54
Show Gist options
  • Save typeoneerror/1512213 to your computer and use it in GitHub Desktop.
Save typeoneerror/1512213 to your computer and use it in GitHub Desktop.
NSMutableAttributedString *attrStr = [NSMutableAttributedString attributedStringWithString:content];
range = NSMakeRange(0, [attrStr length]);
[attrStr setFont:[UIFont fontWithName:LBFontBryantMedium size:16]];
[attrStr setTextAlignment:CTTextAlignmentFromUITextAlignment(UITextAlignmentLeft)
lineBreakMode:CTLineBreakModeFromUILineBreakMode(UILineBreakModeWordWrap)];
[attrStr addAttribute:(NSString *)kCTKernAttributeName
value:[NSNumber numberWithFloat:-0.4]
range:range];
[attrStr addAttribute:(NSString *)kCTParagraphStyleAttributeName
value:(id)[NSAttributedString paragraphStyleWithLineSpacing:7.0f andAlignment:kCTLeftTextAlignment]
range:range];
+ (CTParagraphStyleRef)paragraphStyleWithLineSpacing:(CGFloat)lineSpacing
andAlignment:(CTTextAlignment)alignment
{
CTParagraphStyleSetting settings[] = {
{kCTParagraphStyleSpecifierLineSpacing, sizeof(lineSpacing), &lineSpacing},
{kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment}
};
CTParagraphStyleRef ref = CTParagraphStyleCreate(settings, sizeof(settings) / sizeof(settings[0]));
return ref;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment