- Swift3.0 开发macOS应用程序 (9): 关闭、最小化
- Swift3.0 开发macOS应用程序(6) NSStatus
- Swift3.0 开发macOS应用程序(5) NSAlert
- Swift3.0 开发macOS应用程序(2) NSCollec
- Swift3.0 开发macOS应用程序(3) NSTableV
- Swift3.0 开发macOS应用程序(4) NSArrayC
- Swift3.0 开发macOS应用程序 (8): NSAnim
- Swift3.0 开发macOS应用程序 (10): 添加Doc
- 初学者的macOS开发:第一部分
- Swift3.0 开发macOS应用程序(1) 入门小实例
Xcode默认窗口中3个按钮的显示位于左上角,如下图
![](https://img.haomeiwen.com/i2105518/7b3fdc2b0f5e04a4.png)
如何做成与Google Browser或者Xcode一样,3个按钮是居中显示的呢?通过mac自带的设置手段达到如下效果,如下图:
![](https://img.haomeiwen.com/i2105518/6d1e5fcbc424b2ba.png)
其实很简单,首先要在WindowController中设置
window?.titlebarAppearsTransparent = true
window?.titleVisibility = .hidden
window?.styleMask = [.fullSizeContentView,.titled,.resizable,.miniaturizable,.closable]
有时想做成常用软件CleanMyMac一样,title与3个按钮居中对齐,只需获取Titlebar 的高,然后放入一个等高的CustomView,通过将Label与CustomView居中约束即可达到相应效果。
![](https://img.haomeiwen.com/i2105518/47a4967361056018.png)
取消toolBar属性内的Separator勾,可以实现这样的效果
![](https://img.haomeiwen.com/i2105518/43f75c05c962449e.png)
隐藏TitleBar请看http://www.jianshu.com/p/c2466c67be32
源码如下:github-->demo
网友评论