Last active
September 17, 2015 09:05
-
-
Save jjgod/3268b967485ada50599c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
- (void)drawRect:(NSRect)dirtyRect { | |
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; | |
CGContextSetTextMatrix(context, CGAffineTransformIdentity); | |
CTFontRef font = CTFontCreateUIFontForLanguage(kCTFontUIFontSystem, 12.0, NULL); | |
// Use this to find out the feature identifiers we use below. | |
CFTypeRef features = CTFontCopyAttribute(font, kCTFontFeaturesAttribute); | |
NSLog(@"%@", features); | |
CFRelease(features); | |
NSDictionary* attributes = | |
@{ (id)kCTFontFeatureSettingsAttribute: @[ @{ (id)kCTFontFeatureTypeIdentifierKey: @35, (id)kCTFontFeatureSelectorIdentifierKey: @6 } ] }; | |
CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)attributes); | |
CTFontRef fontWithCenteredColon = CTFontCreateCopyWithAttributes(font, 12.0, NULL, desc); | |
CFRelease(desc); | |
CFRelease(font); | |
NSAttributedString* attrString = [[NSAttributedString alloc] initWithString:@"Hello:World" attributes:@{ (id)kCTFontAttributeName: (__bridge id)fontWithCenteredColon }]; | |
CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString); | |
CFRelease(fontWithCenteredColon); | |
CGContextSetTextPosition(context, 50, 50); | |
CTLineDraw(line, context); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment