macOS编程 NSView改变背景色
来源:互联网 发布:揭阳淘宝村在哪里 编辑:程序博客网 时间:2024/06/05 14:28
和UIView不同, NSView不能直接通过backgroundColor改变背景色
这里总结下NSView用代码改变背景色的两种方法:
第一种:
不自定义子类,直接在layer上改变背景色
NSView *view = [[NSView alloc]init]; view.frame = NSMakeRect(0, 0, 100, 100); view.wantsLayer = YES; view.layer.backgroundColor = [NSColor redColor].CGColor; [self.view addSubview:view];
第二种:
自定义子类,在drawRect方法中改变背景色
- (void)drawRect:(NSRect)dirtyRect { [[NSColor yellowColor] setFill]; NSRectFill(dirtyRect); [super drawRect:dirtyRect];}
资料参考来源:
https://stackoverflow.com/questions/2962790/best-way-to-change-the-background-color-for-an-nsview
阅读全文
0 0
- macOS编程 NSView改变背景色
- 改变背景色
- 对话框改变背景色
- 改变窗口背景色
- 改变Eclipse背景色
- 改变对话框背景色
- 改变对话框背景色
- UISearchBar 改变背景色
- Eclipse 改变背景色
- 改变UISearchBar背景色
- 改变图片背景色
- 改变Toast背景色
- 改变对话框背景色
- 改变Eclipse背景色
- Eclipse背景色改变
- Studio改变背景色
- Cocoa NSView 设置背景色(mac OS X )
- 改变Push Button背景色
- Ubuntu16.04默认安装了Python2和Python3的版本
- Python的MapReduce调用及多输入文件的使用(统计url的点击量)
- 制作大型MMO项目中的相机视角操作
- 设计模式之工厂模式VS抽象工厂模式
- ASP.NET MVC 5
- macOS编程 NSView改变背景色
- Java基础——response.setContentType(...)与response.addHeader(...)
- LeetCode 2. Add Two Numbers
- 在谷歌浏览器安装json格式化插件
- 建立保持时间的介绍与分析
- oracle时间函数
- miniui -- 当前页export to excel
- TF库的使用
- HDU 1285 确定比赛名次 拓扑排序