![](https://img.haomeiwen.com/i7778318/1b9a6ab849fa32cc.png)
- 去掉系统titleBar合并到下面
在MainMenu.xib选中Window,勾选属性Full Size Content View,实现的效果就是titleBar和下面的view合并到一起。
用下面这行代码效果是一样的:
self.window.styleMask = self.window.styleMask | NSWindowStyleMaskFullSizeContentView;
- 全部代码
- (void)createWindowBtn {
//将titleBar和下面的view合并到一起
self.window.styleMask = self.window.styleMask | NSWindowStyleMaskFullSizeContentView;
//设置为点击背景可以移动窗口
[self.window setMovableByWindowBackground:YES];
//设置标题栏透明
self.window.titlebarAppearsTransparent = YES;
//隐藏窗口标题
self.window.titleVisibility = NSWindowTitleHidden;
NSButton *closeBtn = [self.window standardWindowButton:NSWindowCloseButton];
NSButton *miniaturizeBtn = [self.window standardWindowButton:NSWindowMiniaturizeButton];
NSButton *zoomBtn = [self.window standardWindowButton:NSWindowZoomButton];
[self.leftMenuView addSubview:closeBtn];
[self.leftMenuView addSubview:miniaturizeBtn];
[self.leftMenuView addSubview:zoomBtn];
//布局,如果用frame写死,系统按钮可能会移到窗口左下方
[closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.leftMenuView).offset(17);
}];
[miniaturizeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.leftMenuView).offset(17);
}];
[zoomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.leftMenuView).offset(17);
}];
}
参考:
https://www.jianshu.com/p/ff299c351ffd
https://www.jianshu.com/p/620914e3ed11
网友评论