Created
May 17, 2020 18:09
-
-
Save tsuu32/9fe1b61a5491c44ebbdd32e612ddefdb 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
// 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