Skip to content

Instantly share code, notes, and snippets.

@jjgod
Last active September 17, 2015 09:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjgod/3268b967485ada50599c to your computer and use it in GitHub Desktop.
Save jjgod/3268b967485ada50599c to your computer and use it in GitHub Desktop.
- (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