与默认的Mac APP标题栏相比,类似Mac原生应用Reminder的标题栏具有更好的显示效果,标题栏和下方的Content View有效融合,整体风格能够保持一致。
而要实现这种风格,我们只需要对当前NSWindow做如下处理:
self.titlebarAppearsTransparent = true
对于这个属性,Apple官方文档里是这样解释的:
When the value of this property is true, the title bar does not draw its background, which allows all content underneath it to show through. It only makes sense to set this property to true when NSFullSizeContentViewWindowMask is also set.
当titlebarAppearsTransparent
设为true
的时候,title bar将不会绘制其背景,换而言之,title bar将会变成透明的,使其完全和下面的View融为一体。
与此同时,Apple还提到,将这个属性设置为true的同时,我们还需要设置Window
的NSFullSizeContentViewWindowMask
,如以下代码所示:
self.styleMask = [.fullSizeContentView]
本文涉及的完整代码如下:
class MainWindow: NSWindow {
override func awakeFromNib() {
super.awakeFromNib()
self.title = "Star Order"
self.styleMask = [.fullSizeContentView, .titled, .miniaturizable, .resizable, .closable]
self.titlebarAppearsTransparent = true
Utils.positionWindowAtCenter(sender: self)
}
}