Skip to content

Instantly share code, notes, and snippets.

@tsuu32
Created May 17, 2020 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsuu32/9fe1b61a5491c44ebbdd32e612ddefdb to your computer and use it in GitHub Desktop.
Save tsuu32/9fe1b61a5491c44ebbdd32e612ddefdb to your computer and use it in GitHub Desktop.
// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/TextUILayer/Tasks/CreateTextViewProg.html
// To execute it, run:
// `$ clang textview_sample.m -framework Cocoa && ./a.out`
#import <Cocoa/Cocoa.h>
int main() {
@autoreleasepool {
NSApplication* app = [NSApplication sharedApplication];
[app setActivationPolicy: NSApplicationActivationPolicyRegular];
NSWindow *aWindow = [[[NSWindow alloc]
initWithContentRect: NSMakeRect(0, 0, 200, 200)
styleMask: NSWindowStyleMaskTitled
backing: NSBackingStoreBuffered
defer: NO
] autorelease];
NSRect cFrame = [[aWindow contentView] frame];
NSTextView *theTextView = [[NSTextView alloc] initWithFrame:cFrame];
NSLog(@"%@", [theTextView markedTextAttributes]);
NSDictionary *theAttributes =
@{ NSBackgroundColorAttributeName: [NSColor blackColor],
NSForegroundColorAttributeName: [NSColor whiteColor],
NSUnderlineStyleAttributeName: @(NSUnderlineStyleDouble | NSUnderlinePatternDot) };
[theTextView setMarkedTextAttributes:theAttributes];
NSLog(@"%@", [theTextView markedTextAttributes]);
[aWindow setContentView:theTextView];
[aWindow cascadeTopLeftFromPoint:NSMakePoint(20,20)];
[aWindow makeKeyAndOrderFront:nil];
[aWindow makeFirstResponder:theTextView];
[NSApp activateIgnoringOtherApps:YES];
[app run];
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment