Created
July 18, 2012 14:32
-
-
Save debuggerman/3136530 to your computer and use it in GitHub Desktop.
Using attributed string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CFMutableAttributedStringRef attributedString = NULL; | |
CFRange stringRange = CFRangeMake(0, CFAttributedStringGetLength(attributedString)); | |
//color | |
CGColorRef stringColor = nil; | |
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB(); | |
CGFloat colorComponents[] = {0.0f, 0.0f, 0.0f, 1.0f}; | |
stringColor = CGColorCreate(rgbColorSpace, colorComponents); | |
CGColorSpaceRelease(rgbColorSpace); | |
CFAttributedStringSetAttribute( | |
attributedString, | |
stringRange, | |
kCTForegroundColorAttributeName, | |
stringColor); | |
//font | |
CTFontRef font = nil; | |
CTFontDescriptorRef mainDescriptor = CTFontDescriptorCreateWithNameAndSize((CFStringRef)@"AGaramondPro-Regular", 0.0); | |
font = CTFontCreateWithFontDescriptor(mainDescriptor, FONT_SIZE, NULL); | |
CFAttributedStringSetAttribute(attributedString, stringRange, kCTFontAttributeName, font); | |
//paragraph | |
CTTextAlignment alignment = kCTRightTextAlignment; | |
CGFloat lineSpacing = -30.0f; | |
CGFloat paragraphSpacing = 10.0f; | |
CTParagraphStyleSetting _settings[] = { | |
{kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment}, | |
{kCTParagraphStyleSpecifierMaximumLineSpacing, sizeof(lineSpacing), &lineSpacing}, | |
{kCTParagraphStyleSpecifierParagraphSpacing, sizeof(paragraphSpacing), ¶graphSpacing} | |
}; | |
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(_settings, sizeof(_settings) / sizeof(_settings[0])); | |
// set paragraph style attribute | |
CFAttributedStringSetAttribute(attributedString, stringRange, kCTParagraphStyleAttributeName, paragraphStyle); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment