• Stars
    star
    1,114
  • Rank 41,670 (Top 0.9 %)
  • Language
    Swift
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A showcase of the many different styles of windows possible with NSWindow on macOS

Swift NSWindow Style Showcase

Swift 5 Platform Github

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 custom 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. Vibrant background with transparent titlebar and no window controls

A vibrant window with a standard border radius and no window controls or title.

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

window?.styleMask.insert(.titled)

window?.titlebarAppearsTransparent = true
window?.titleVisibility = .hidden

window?.standardWindowButton(.miniaturizeButton)?.isHidden = true
window?.standardWindowButton(.closeButton)?.isHidden = true
window?.standardWindowButton(.zoomButton)?.isHidden = true

window?.isMovableByWindowBackground = true

8. Transparent titlebar

A window with a transparent titlebar.

window?.titlebarAppearsTransparent = true

9. Transparent titlebar with background color

Same as above with a background color.

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

10. Toolbar

A window with a toolbar.

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

11. Transparent toolbar

Same as above, with the toolbar transparent.

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

12. 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

13. 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

14. 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

15. 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"))

16. 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"))

17. macOS Mojave dark mode

The macOS Mojave dark mode appearance.

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

More Repositories

1

Pine

A modern, native macOS markdown editor
Swift
3,309
star
2

ion

A lightweight CSS framework that brings MacOS styled elements to Electron
CSS
147
star
3

OpenQuickly

A custom 'open quickly' window that imitates macOS' Spotlight
Swift
122
star
4

hackd

A modern Hacker News iOS application, built with React Native
JavaScript
97
star
5

markr

Minimalistic markdown editor for MacOS with live preview
Swift
87
star
6

plyr

A hyperminimal, lightweight macOS desktop music application
Swift
50
star
7

dotfiles

MacOS dotfiles with an easy installation script
Emacs Lisp
20
star
8

mdtg

Quickly generate markdown tables in your terminal using a simplistic specification
Rust
16
star
9

BitStream

A rudimentary Electron application that utilises WebTorrent to stream and download a torrent simultaneously
JavaScript
15
star
10

hkn

A go module for interacting with Hacker News
Go
13
star
11

crypticker

A simple command line program to get current cryptocurrency data
Go
11
star
12

neon

Neon is a simple code editor for MacOS, that runs from the menubar.
JavaScript
10
star
13

Swift-NSUserNotificationPrivate

MacOS NSUserNotification Private API in Swift 4. Simple demonstration of undocumented notification features.
Objective-C
9
star
14

pickur-swift

Pickur is a simple colour converter written in swift. It converts HEX/RGB colours to NS/UI/HEX/RGB colours.
Swift
7
star
15

TikZi

A simple TikZ editor, viewer and exporter
Swift
6
star
16

rails-ecommerce

An ecommerce site built using rails. Includes: users, products, carts, orders, categories, multiple images, custom pages, image banners and more
Ruby
5
star
17

itunes-artworker

Python script to download iTunes album art
Python
5
star
18

lukakerr.github.io

Github pages site, built with jekyll
HTML
4
star
19

lightweight-slider

A very lightweight (~2.5kb), minimal, easy to use image slider/carousel. No jQuery, no dependencies
JavaScript
4
star
20

Sea

A simple lexer, parser and evaluator for a C like language
Haskell
3
star
21

latex-templates

LaTeX templates I've created that have been useful when writing math/computing/engineering assignments at uni
TeX
3
star
22

sublime-autotheme

A small script to change your sublime text theme for day and night. Made for MacOS.
Shell
3
star
23

homebrew-things

A repository containing casks and formula for my applications/scripts
Ruby
2
star
24

two-tone

Minimalistic CSS framework with light or dark options, completely responsive. Currently a work in progress
CSS
1
star