• Stars
    star
    1,064
  • Rank 43,399 (Top 0.9 %)
  • Language
    Objective-C
  • License
    BSD 2-Clause "Sim...
  • Created over 13 years ago
  • Updated over 8 years ago

Reviews

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

Repository Details

NSWindow subclass with a highly customizable title bar and traffic lights

INAppStoreWindow

Title bar and traffic light customization for NSWindow

INAppStoreWindow is an NSWindow subclass that was originally developed to mimic the appearance of the main window in the Mac App Store application introduced in OS X 10.6.6.

The MAS application has since transitioned away from this design, but INAppStoreWindow is still being actively developed to provide extensive additional customization options for NSWindow title bars.

INAppStoreWindow

Features of INAppStoreWindow:

  • No private API usage and Mac App Store friendly.
  • Fully customizable title bar view -- add subviews (toolbars, buttons, etc.) and block based drawing for custom backgrounds
  • Adjustable title bar height
  • Customization of the traffic light/fullscreen buttons for all button states.
  • Customization of the window title text.
  • Works on OS X versions 10.6-10.9
  • Compatible with full screen mode in OS X 10.7+

All of these great apps are using INAppStoreWindow in production!

Usage

ARC

INAppStoreWindow now requires ARC to compile. If your project does not use ARC, compile INAppStoreWindow.m with the -fobjc-arc linker flag.

Basic Configuration

Using INAppStoreWindow is as easy as changing the class of the NSWindow in Interface Builder, or simply by creating an instance of INAppStoreWindow in code (if you're doing it programmatically). I've included a sample project demonstrating how to use INAppStoreWindow.

NOTE: The title bar height is set to the standard window title height by default. You must set the 'titleBarHeight' property in order to increase the height of the title bar.

Some people seem to be having an issue where the title bar height property is not set properly when calling the method on an NSWindow without typecasting it to the INAppStoreWindow class. If you are experiencing this issue, do something like this (using a window controller, for example):

INAppStoreWindow *aWindow = (INAppStoreWindow*)[windowController window];
aWindow.titleBarHeight = 60.0;

Adding buttons and other controls to the title bar

Adding controls and other views to the title bar is simple. This can be done either programmatically or through Interface Builder. Here are examples of both methods:

Programmatically

// This code places a 100x100 button in the center of the title bar view
NSView *titleBarView = self.window.titleBarView;
NSSize buttonSize = NSMakeSize(100.f, 100.f);
NSRect buttonFrame = NSMakeRect(NSMidX(titleBarView.bounds) - (buttonSize.width / 2.f), NSMidY(titleBarView.bounds) - (buttonSize.height / 2.f), buttonSize.width, buttonSize.height);
NSButton *button = [[NSButton alloc] initWithFrame:buttonFrame];
[button setTitle:@"A Button"];
[titleBarView addSubview:button];

Interface Builder

NOTE: Even though the content layout for the title bar can be done in Interface Builder, you still need to use the below code to display the view created in IB in the title bar.

// self.titleView is a an IBOutlet to an NSView that has been configured in IB with everything you want in the title bar
self.titleView.frame = self.window.titleBarView.bounds;
self.titleView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
[self.window.titleBarView addSubview:self.titleView];

Centering the traffic light and full screen buttons

The vertical centering of the traffic light and full screen buttons can be controlled through two properties: centerTrafficLightButtons and centerFullScreenButton.

The traffic light buttons are vertically centered by default.

Hiding the title bar in fullscreen

You can tell INAppStoreWindow to hide when entering fullscreen mode, and reappear on exit. Just set the property hideTitleBarInFullScreenin order to hide it.

Padding the traffic lights and fullscreen buttons

The left padding of the traffic lights can be adjusted with trafficLightButtonsLeftMargin and the right padding of the fullscreen button can be adjusted with fullScreenButtonRightMargin.

Hiding the baseline (divider line between the titlebar and the content view)

The baseline divider can be hidden by setting showsBaselineSeparator to NO, the default value is YES.

Customizing traffic lights buttons

In order to customize these buttons, you would use INWindowButton class. You must create a separate instance for each button and provide your graphics for each state of the button. Currently the following states are supported:

  • Active
  • Active in not main window
  • Inactive (disabled)
  • Rollover
  • Pressed

Please refer to INWindowButton.h header documentation for more details.

Customizing window's title appearance

You can enable title drawing by setting showsTitle property to YES. For NSDocument based apps, you can enable drawing the document proxy icon by setting showsDocumentProxyIcon property to YES. You can adjust appearance using titleTextColor, inactiveTitleTextColor, titleTextShadow, and inactiveTitleTextShadow properties. Also, you can enable title drawing in fullscreen by setting showsTitleInFullscreen property to YES.

Using your own drawing code

A lot of time and effort has gone into making the custom titlebar in INAppStoreWindow function just right, it would be a shame to have to re-implement all this work just to draw your own custom title bar. So INAppStoreWindow has a titleBarDrawingBlock property that can be set to a block containing your own drawing code!

Custom Window

[self.window setTitleBarDrawingBlock:^(BOOL drawsAsMainWindow, CGRect drawingRect, CGRectEdge edge, CGPathRef clippingPath){
    // Custom drawing code!    
}];

This block gets passed some useful parameters like if the window is the main one(drawsAsMainWindow), the drawing rect of the title bar(drawingRect), and a pre-made clipping path with rounded corners at the top(clippingPath).

Setting the title bar colors

If you just want to adjust the color of the title bar without drawing the whole thing yourself, there are a few properties to help you do so:

self.window.titleBarStartColor     = [NSColor colorWithCalibratedWhite: 0.6 alpha: 1.0];
self.window.titleBarEndColor       = [NSColor colorWithCalibratedWhite: 0.9 alpha: 1.0];
self.window.baselineSeparatorColor = [NSColor colorWithCalibratedWhite: 0.2 alpha: 1.0];

self.window.inactiveTitleBarEndColor       = [NSColor colorWithCalibratedWhite: 0.95 alpha: 1.0];
self.window.inactiveTitleBarStartColor     = [NSColor colorWithCalibratedWhite: 0.8  alpha: 1.0];
self.window.inactiveBaselineSeparatorColor = [NSColor colorWithCalibratedWhite: 0.4  alpha: 1.0];

Extensions

Additional extensions for INAppStoreWindow are provided in the Extensions subfolder.

NSDocument+INAppStoreWindowFixes

Add this category to your project to fix title bar layout for document based apps in response to -[NSDocument updateChangeCount:]. This fix was separated from the main INAppStoreWindow codebase because it swizzles methods on NSDocument.

INTitlebarView+CoreUIRendering

Add this category to your project to use CoreUI to render the system default title bar gradient, noise texture, and baseline separator. This will provide the most accurate visual results. You should only add this category to your project if you intend to release outside the App Store!

If you use this category you must define the preprocessor symbol INAPPSTOREWINDOW_NO_COREUI with a value of 1 in the build configuration for your Mac App Store version in order to exclude this code because it uses private APIs and will result in rejection if included in a Mac App Store submission.

When CoreUI rendering is not available, INAppStoreWindow will emulate the rendering of the system title bar as closely as possible.

C# Port (Unofficial)

AppStoreWindow is a pure MonoMac implementation of INAppStoreWindow by @ashokgelal.

Authors

INAppStoreWindow is maintained by Indragie Karunaratne, who could not have done it without many awesome contributors.

Licensing

INAppStoreWindow is licensed under the BSD license.

More Repositories

1

InAppViewDebugger

A UIView debugger (like Reveal or Xcode) that can be embedded in an app for on-device view debugging
Swift
1,871
star
2

CocoaMarkdown

Markdown parsing and rendering for iOS and OS X
Objective-C
1,200
star
3

DominantColor

Finding dominant colors of an image using k-means clustering
Swift
959
star
4

MarkdownTextView

Rich Markdown editing control for iOS
Swift
686
star
5

SwiftAutoLayout

Tiny Swift DSL for Autolayout
Swift
655
star
6

SNRHUDKit

Code drawn AppKit HUD interface elements
Objective-C
326
star
7

swiftrsrc

Resource code generation tool for Swift
Swift
290
star
8

INDANCSClient

Objective-C Apple Notification Center Service Client
Objective-C
252
star
9

INPopoverController

A customizable popover controller for OS X
Objective-C
196
star
10

SNRSearchIndex

SearchKit backed search for Core Data
Objective-C
190
star
11

Unzip

iOS 8 Action Extension for browsing ZIP files
Objective-C
165
star
12

NSUserNotificationPrivate

Private API showcase for NSUserNotification on OS X
Objective-C
152
star
13

SNRMusicKit

All-in-one framework for browsing and playing music from various sources on iOS and OS X
Objective-C
150
star
14

WWDC-2014

Scholarship submission for WWDC 2014
Objective-C
146
star
15

Ares

Zero-setup P2P file transfer between Macs and iOS devices
Swift
133
star
16

INDockableWindow

A window to which other views can be "docked" to and separated into their own windows
Objective-C
114
star
17

INDLinkLabel

A simple, no frills UILabel subclass with support for links
Swift
82
star
18

SNRFetchedResultsController

Automatic Core Data change tracking for OS X (NSFetchedResultsController port)
Objective-C
81
star
19

INDSequentialTextSelectionManager

Sequential text selection for NSTextViews
Objective-C
74
star
20

OEGridView

High performance Core Animation-based grid view, originally from OpenEmu.
Objective-C
72
star
21

INDGIFPreviewDownloader

[iOS] Retrieves preview images for GIFs by downloading only the first frame
Objective-C
60
star
22

Chip8

CHIP-8 emulator and disassembler written in Swift
Swift
53
star
23

pdfcat

OS X utility for concatenating PDF files
Swift
49
star
24

ReactiveXPC

Signals across process boundaries
Swift
36
star
25

ObjectiveKVDB

Objective-C wrapper for kvdb (https://github.com/dinhviethoa/kvdb)
Objective-C
33
star
26

SwiftTableViews

Type-safe Table Views with Swift
Swift
33
star
27

AlamofireRACExtensions

ReactiveCocoa Swift extensions for Alamofire
Swift
32
star
28

Dial

The beginnings of a replacement Contacts app for iOS.
Objective-C
30
star
29

ReactiveBLE

ReactiveCocoa wrapper for communicating with BLE devices using CoreBluetooth
Objective-C
29
star
30

INSOCKSServer

SOCKS5 proxy server implementation in Objective-C
Objective-C
27
star
31

LiveWebPreview

Web development tool for automatically refreshing a page when the content changes.
Objective-C
20
star
32

SNRLastFMEngine

[DEPRECATED] A modern block-based Objective-C interface to the Last.fm API
Objective-C
19
star
33

AttributedString.swift

Swift library that adds type safety and string interpolation support to NSAttributedString
Swift
18
star
34

INKeychainAccess

[DEPRECATED] Objective-C Keychain Services Wrapper for OS X and iOS
Objective-C
17
star
35

tecs

Projects for The Elements of Computing Systems by Nisan and Schocken
Assembly
15
star
36

INTrafficLightsDisabler

SIMBL plugin to hide the traffic lights on Mac OS X
Objective-C
14
star
37

pebble-lifx

Pebble controller for LIFX bulbs. UAlberta CompE Club Hackathon 2014 project.
Objective-C
11
star
38

xcode-themes

Color themes for Xcode 4 and 5
6
star
39

radars

Apple Radars filed for OS X and iOS.
Objective-C
5
star
40

indragiek.github.com

http://indragie.com
HTML
3
star
41

arduino-copter

Copter game for Arduino + Adafruit TFT
C++
2
star
42

writing

Things that I write
2
star
43

advent-of-code-2020

My Rust solutions for https://adventofcode.com
Rust
1
star
44

bootstrap-no-responsive

Compiled Bootstrap with responsive features disabled
1
star