功能描述:
1. 可以把代码复制过来,并保持原来的高亮状态
2. 提供黑 白两种不同的背景状态切换
3. 支持窗口放大和缩小
4. 最重要的是: 该窗口一直置顶(当不再需要了可以按command + h 隐藏或退出程序)
5. 支持选择图片(比如代码的截图)
效果如下:
代码如下:
//
// ViewController.m
// mac_02_window
//
// Created by beyond on 2018/6/5.
// Copyright © 2018年 beyond. All rights reserved.
//
#import "ViewController.h"
#import <Quartz/Quartz.h>
@interface ViewController()<NSWindowDelegate>
{
NSWindow *_win;
NSTextView *_textView;
NSScrollView *_scrollView;
NSButton *_switchBtn;
NSButton *_chooseImgBtn;
NSImageView *_imgView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSApplication* app = [NSApplication sharedApplication];
//Create the main window
NSRect rc = NSMakeRect(750, 1, 600, 350);
NSUInteger uiStyle = NSTitledWindowMask | NSResizableWindowMask | NSClosableWindowMask;
NSBackingStoreType backingStoreStyle = NSBackingStoreBuffered;
NSWindow* win = [[NSWindow alloc] initWithContentRect:rc styleMask:uiStyle backing:backingStoreStyle defer:NO];
[win setTitle:@"代码->顶置"];
[win makeKeyAndOrderFront:win];
// 给window添加一个NSTextField
NSTextView *textField = [[NSTextView alloc]initWithFrame:win.contentView.frame];
// textField.backgroundColor = [NSColor colorWithRed:29/255.0 green:30/255.0 blue:25/255.0 alpha:1];
textField.backgroundColor = [NSColor colorWithRed:29/255.0 green:30/255.0 blue:25/255.0 alpha:1];
tex