在MacOS上使用NSWindow展示了多种不同风格的窗口

这篇具有很好参考价值的文章主要介绍了在MacOS上使用NSWindow展示了多种不同风格的窗口。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Swift NSWindow Style Showcase

 

 

A showcase of many of the different styles of windows possible with NSWindow on MacOS. In some examples, NSToolbar, and NSVisualEffectView are used. No private API's are used.

To test each style, clone the project, open it in Xcode, uncomment each block of code in WindowController.swift and run. The numbers above each block correspond to each style below.

All code is in WindowController.swift in the windowDidLoad function. You should just be able to place each block inside that function to get the exact same result.

If you have a style to add, please make a pull request.

1. Hide title

Don't show the title text in the titlebar.

window?.titleVisibility = .hidden

2. Hide titlebar

Hide the titlebar completely.

window?.styleMask.remove(.titled)

3. Vibrant background

Create a vibrant background where whatever is behind the window can be slightly seen. This uses NSVisualEffectView.

let visualEffect = NSVisualEffectView()
visualEffect.blendingMode = .behindWindow
visualEffect.state = .active
visualEffect.material = .dark
window?.contentView = visualEffect

visualEffect.material can take multiple values including:

  • .appearanceBased: based on the views appearance
  • .dark: dark appearance
  • .ultraDark: ultra dark appearance
  • .light: light appearance
  • .mediumLight: medium light appearance
  • others such as .menu.popover.selection.sidebar and .titlebar

4. Vibrant background with transparent titlebar

Same as above, with a transparent titlebar.

let visualEffect = NSVisualEffectView()
visualEffect.blendingMode = .behindWindow
visualEffect.state = .active
visualEffect.material = .dark
window?.contentView = visualEffect

window?.titlebarAppearsTransparent = true
window?.styleMask.insert(.fullSizeContentView)

5. Vibrant background without titlebar

Same as above, without the titlebar.

let visualEffect = NSVisualEffectView()
visualEffect.blendingMode = .behindWindow
visualEffect.state = .active
visualEffect.material = .dark
window?.contentView = visualEffect

window?.styleMask.remove(.titled)
window?.isMovableByWindowBackground = true

6. Vibrant background with border radius and no titlebar

A vibrant window with a custom border radius. The border radius value can be changed at visualEffect.layer?.cornerRadius = 16.0.

let visualEffect = NSVisualEffectView()
visualEffect.translatesAutoresizingMaskIntoConstraints = false
visualEffect.material = .dark
visualEffect.state = .active
visualEffect.wantsLayer = true
visualEffect.layer?.cornerRadius = 16.0

window?.titleVisibility = .hidden
window?.styleMask.remove(.titled)
window?.backgroundColor = .clear
window?.isMovableByWindowBackground = true

window?.contentView?.addSubview(visualEffect)

guard let constraints = window?.contentView else {
  return
}

visualEffect.leadingAnchor.constraint(equalTo: constraints.leadingAnchor).isActive = true
visualEffect.trailingAnchor.constraint(equalTo: constraints.trailingAnchor).isActive = true
visualEffect.topAnchor.constraint(equalTo: constraints.topAnchor).isActive = true
visualEffect.bottomAnchor.constraint(equalTo: constraints.bottomAnchor).isActive = true

7. Transparent titlebar

A window with a transparent titlebar.

window?.titlebarAppearsTransparent = true

8. Transparent titlebar with background color

Same as above with a background color.

window?.titlebarAppearsTransparent = true
window?.backgroundColor = .red

9. Toolbar

A window with a toolbar.

let customToolbar = NSToolbar()
window?.titleVisibility = .hidden
window?.toolbar = customToolbar

10. Transparent toolbar

Same as above, with the toolbar transparent.

let customToolbar = NSToolbar()
window?.titlebarAppearsTransparent = true
window?.titleVisibility = .hidden
window?.toolbar = customToolbar

11. Transparent toolbar without seperator

Same as above, without the toolbar seperator.

let customToolbar = NSToolbar()
customToolbar.showsBaselineSeparator = false
window?.titlebarAppearsTransparent = true
window?.titleVisibility = .hidden
window?.toolbar = customToolbar

12. Transparent toolbar with background color and without seperator

Same as above, with a background color.

let customToolbar = NSToolbar()
customToolbar.showsBaselineSeparator = false
window?.titlebarAppearsTransparent = true
window?.titleVisibility = .hidden
window?.backgroundColor = .red
window?.toolbar = customToolbar

13. Translucent toolbar

A translucent toolbar allowing for content behind the toolbar to be slightly seen.

let customToolbar = NSToolbar()
window?.titleVisibility = .hidden
window?.styleMask.insert(.fullSizeContentView)
window?.contentView?.wantsLayer = true
window?.contentView?.layer?.contents = NSImage(named: NSImage.Name("Background"))
window?.toolbar = customToolbar

14. Translucent titlebar

Same as above with a titlebar instead of a toolbar.

window?.titleVisibility = .hidden
window?.styleMask.insert(.fullSizeContentView)
window?.contentView?.wantsLayer = true
window?.contentView?.layer?.contents = NSImage(named: NSImage.Name("Background"))

15. Transparent titlebar without title

Same as above with a transparent titlebar.

window?.titleVisibility = .hidden
window?.styleMask.insert(.fullSizeContentView)
window?.titlebarAppearsTransparent = true
window?.contentView?.wantsLayer = true
window?.contentView?.layer?.contents = NSImage(named: NSImage.Name("Background"))

16. macOS Mojave dark mode

The macOS Mojave dark mode appearance.文章来源地址https://www.toymoban.com/news/detail-732672.html

if #available(OSX 10.14, *) {
  window?.appearance = NSAppearance(named: .darkAqua)
}

到了这里,关于在MacOS上使用NSWindow展示了多种不同风格的窗口的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • MacOS Wireshark打开多窗口解决方案

            在macOS环境下,wireshark默认无法同时打开多个窗口,当需要分析、比较多个文件时相比相对麻烦。以下记录两种解决该问题的方案。 终端环境下配合“-n”、“-a”参数使用open命令打开多个窗口 实际也是使用open命令,但是借助macOS自带的自动操作应用程序可以实现

    2024年02月12日
    浏览(26)
  • macOS Sonoma 14 Beta3官方最新版VMware虚拟机安装全套图文教程(两种不同的安装流程图,极限傻瓜流程)

    如今macOS最新的Sonoma 14版本已更新至Beta3。总的来说在VMware虚拟机中的安装流程都差不多,需要注意的是由于网络的问题,可分为有网安装和无网络模式安装。不同模式的安装流程稍微有点区别,如果你真的不会安装,这篇傻瓜版的流程一定是你的不二之选。之前我也发表过关

    2024年02月13日
    浏览(34)
  • 【云原生 | 02】分别在CentOS、Ubuntu、macOS、win7、win8、win10等不同操作系统下安装Docker详细教程

    🍁 博主简介 :         🏅云计算领域优质创作者         🏅2022年CSDN新星计划python赛道第一名         🏅2022年CSDN原力计划优质作者         🏅阿里云ACE认证高级工程师         🏅阿里云开发者社区专家博主 💊 交流社区 :CSDN云计算交流社区欢迎您的

    2024年01月17日
    浏览(56)
  • MacOS使用CMake

    CMake是开源、跨平台的编译和打包工具,在有跨平台需求的项目里面,CMake是常用的工具。它可以根据目标平台生成不同的Makefile或者工程文件,生成Makefile后使用make编译代码。本文介绍CMake的安装和入门使用。 安装CMake 使用brew安装cmake,等待安装完成即可 如果没有homebrew,首

    2024年02月05日
    浏览(36)
  • Homebrew使用教程(macOS)

    Homebrew是一个开源的软件包管理工具,它的主要开发语言是Ruby,项目托管在GitHub上。 目前,Homebrew只能通过命令行终端使用,没有图形化操作界面。因此,这个工具更适合有编程基础的人使用。 官方介绍,Homebrew可以用在macOS系统或Linux系统上管理软件包。但实际上,它在Li

    2024年02月10日
    浏览(32)
  • macOS - 使用VLC

    VLC media player VLC 是一款自由、开源的跨平台多媒体播放器及框架,可播放大多数多媒体文件,以及 DVD、音频 CD、VCD 及各类流媒体协议。 VLC 官网: https://www.videolan.org/vlc/ 方式一:下载安装包 下载地址 VLC for Mac OS X https://www.videolan.org/vlc/download-macosx.html 方式二:使用 brew 安装

    2024年02月04日
    浏览(26)
  • MacBook Pro(13 英寸,2011 年末)A1278 官方最高支持macOS High Sierra,使用macOS Catalina Patcher成功安装macOS Catalina

    MacBook Pro(13 英寸,2011 年末)A1278 ,这台超过10年的老本子,原本安装的是Mac OS X 10.7 \\\"Lion\\\"。在线重装系统,怎么尝试都不成功。 在官网社区上,找到一个官方制作macOS启动U盘的方法,而且有链接可下载各个版本的OS。 如何创建可引导的 macOS 安装器 - Apple 支持 (中国) 安装

    2024年02月02日
    浏览(37)
  • Macos下安装使用Redis

    Redis 是一个基于内存的key-value的结构数据库 适合存储热点数据 https://redis.io/docs/getting-started/installation/install-redis-on-mac-os/ 安装redis 查看安装信息: 前台启动redis: 后台启动redis: 查看信息: 停止: 配置 打开 /opt/homebrew/etc/redis.conf 配置文件 修改密码 登录redis 字符串 哈希 列表

    2024年02月06日
    浏览(34)
  • MacOS 无法使用Wget工具

    MacOS 报错提示 1. 执行以下命令,安装wget命令工具。如果提示缺少 brew 依赖,参照下一节安装 Homebrew 部分解决问题。 2. 验证wget工具。 1. 进入官网,Homebrew — The Missing Package Manager for macOS (or Linux) 2. 复制安装命令 3. MacOS命令行,执行命令。 4. 验证brew工具,执行 brew -v 命令。

    2024年02月22日
    浏览(29)
  • MacOS下安装和使用JMeter

    大家好,我是中国码农摘星人。 欢迎分享/收藏/赞/在看! JMeter 是建立在 JDK8 或 JDK9 的环境下运行的,因此在安装 JMeter 之前需要先安装 JDK。 详见文章:安装及配置JDK 官网 - Download Apache JMeter 使用 tar 命令解压并存放到相应目录下,笔者将文件放到了 /usr/local/JMeter/JMeter-5.5 下

    2024年02月11日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包