Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
- (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
You can’t perform that action at this time.