• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    Objective-C
  • Created over 13 years ago
  • Updated about 6 years ago

Reviews

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

Repository Details

A subclass of NSWindowController that provides an easy way to create preference windows.

DBPrefsWindowController

Originally created by Dave Batton.

Application preference windows aren’t difficult to create. Just create an NSWindowController, set up a toolbar, create a nib file with either a series of custom views, or with an NSTabView object. The problem is, just setting up the toolbar and view swapping mechanism takes a lot of code, and it’s basically the same for every application. Sounds like an excellent opportunity to create a new class.

The goal of DBPrefsWindowController is to reduce the overhead of creating preference tabs to one line of code for each toolbar icon. This is achieved with an NSWindowController subclass named DBPrefsWindowController.

Using DBPrefsWindowController

If you’re comfortable with subclassing and working with Interface Builder, you’ll be able to figure out how to use it from the included example project. Basically you just subclass it and connect your .h file to a nib file of custom views. The nib file should be named Preferences. Then just call -addView:label: to specify which views to display and what labels to use:

- (void)setupToolbar
{
    [self addView:generalPreferenceView label:@"General"];
    [self addView:colorsPreferenceView label:@"Colors"];
    [self addView:playbackPreferenceView label:@"Playback"];
    [self addView:updatePreferenceView label:@"Update"];
    [self addView:advancedPreferenceView label:@"Advanced"];
}

When setup this way, DBPrefsWindowController will look for image files with names that match the labels supplied here. If your application is localized, you can instead call -addView:label:image: to specify the images to use for the toolbar icons.

That’s really all there is to it. If you’ve already created a nib file with separate views for your preferences window, you can just use it instead of creating a new nib file. Either rename your nib file Preferences, or override the +nibName class method so it returns the name of your existing nib file.

Documentation

The DBPrefsWindowController class is designed to be subclassed for each application in which it is used. The subclass should be set as the File’s Owner for a nib file named “Preferences.” The subclass should have NSView instances which are IBOutlets connected to views in the nib file.

The nib file does not need to be connected to a window. If it is, it will be ignored and a new window will be created to display the preference views.

+ (DBPrefsWindowController *)sharedPrefsWindowController

This class method returns a shared instance of the DBPrefsWindowController class.

+ (NSString *)nibName

Override this class if you want to use a nib file named something other than Preferences.

- (void)setupToolbar

Override this method with calls to -addView:label: or -addView:label:image: to populate the toolbar.

- (void)addView:(NSView *)view label:(NSString *)label

Call this method as many times as needed from -setupToolbar to add new toolbar icons and custom views to the preferences window. An image with a name that matches the label should be available in the application bundle. It will be used as the toolbar icon.

- (void)addView:(NSView *)view label:(NSString *)label image:(NSImage *)image

This method can be used instead of -addView:label: if the application is localized, or if you just want to use icons with names that differ from the toolbar button labels.

- (IBAction)showWindow:(id)sender

Call this method to display the preferences window. For example: [[AppPrefsWindowController sharedPrefsWindowController] showWindow:nil];

- (void)setCrossFade:(BOOL)fade`

Call this method to enable or disable the cross-fade effect when switching views. The default value is YES.

- (void) setShiftSlowsAnimation:(BOOL)slow

Call this method to enable or disable the use of the shift key to slow down the animation when switching views. The default value is YES.

More Repositories

1

KGNoise

Cocoa noise drawing code plus a ready to go noise view!
Objective-C
776
star
2

KGModal

KGModal is an easy drop in control that allows you to display any view in a modal popup.
Objective-C
453
star
3

InAppSettings

InAppSettings provides a view controller that displays the application's Settings.bundle as it appears in the iPhone settings. Allowing the same preferences in app and in the iPhone settings.
Objective-C
233
star
4

Hark

An example Text to Speech App
Swift
186
star
5

BBlock

Objective-c block categories and subclasses
Objective-C
168
star
6

KGNAutoLayout

Making AutoLayout Easy
Swift
124
star
7

KGDiscreetAlertView

An easy drop in control that allows you to display a discrete alert in any view.
Objective-C
101
star
8

KGKeyboardChangeManager

A block-based wrapper around the hairy world of iOS keyboard notifications and frames
Objective-C
93
star
9

Spectttator

Spectttator is an Objective-C framework for OSX and iOS that makes it easy to asynchronously interact with the dribbble api.
Objective-C
86
star
10

UIImage-Vector

UIImage category for dealing with vector formats like PDF and icon fonts.
Objective-C
73
star
11

KGNotePad

KGNotePad is a text view complete with lines and torn paper.
Objective-C
71
star
12

PaintCodeExample

An example iPhone app using PaintCode and BBlock
Objective-C
68
star
13

KGPixelBoundsClip

NSImage and UIImage category that provides methods to find the pixel bounds of an image and create a new image clipped to those bounds.
Objective-C
62
star
14

LinenClipView

Adds a linen pattern behind scrollviews like in Apple's Lion apps.
Objective-C
58
star
15

LaunchAtLoginHelper

A helper app to launch a main app at login under sandboxing
Objective-C
57
star
16

EyeTunes

This is a git-svn fork of the EyeTunes project with support for iTunes 10.
Objective-C
34
star
17

KGNPreferredFontManager

Helper class to registering custom fonts for UIFontTextStyle
Swift
21
star
18

JSONMagic

JSONMagic makes it easy to traverse and parse JSON in Swift.
Swift
19
star
19

UIColorCategories

Category methods UIColor
Objective-C
15
star
20

SCKeyRecorder

An Objective-C shortcut recorder for the Mac.
Objective-C
15
star
21

Coaches-Loupe

Upload shots to dribbble.com
C
14
star
22

KGJSON

A simple category around NSJSONSerialization for common JSON string operations
Objective-C
13
star
23

BBBouncePass

An Objective-C library for uploading shots to Dribbble.
Objective-C
12
star
24

KGNGradientView

KGNGradientView is a collection UIView subclasses for linear and radial gradients.
Swift
10
star
25

pygml

A python library for reading and writing gml files.
Python
9
star
26

KGLib

Cocoa library code
Objective-C
8
star
27

KGNCameraController

A camera view build on top of AVFoundation
Objective-C
7
star
28

Gister

Cocoa app for viewing gists.
Objective-C
7
star
29

KGNColor

A collection of UIColor extensions
Swift
7
star
30

BirdHouseKit

An AFNetworking based Twitter library(unfinished)
Objective-C
6
star
31

UIView-KGNAutoLayout

Auto Layout helper methods for common layout operations.
Objective-C
6
star
32

ShapecatcherKit

An Objective-CFramework for the shapecatcher.com api
Objective-C
5
star
33

ImageViewPlus

A Safari Extension that adds formatting to the image view page.
JavaScript
5
star
34

kgn_icons

Icons
Python
5
star
35

KGNThread

A collection of helpful methods that wrap GCD
Swift
4
star
36

NSData-Base64

Git repo of http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html
Objective-C
4
star
37

IcnsFactory

Create Mac Icons(.icns) from Cocoa
Objective-C
3
star
38

TimeDisplay

A python package for displaying time deltas and runtimes as nice readable strings.
Python
3
star
39

cssutils

git clone
Python
3
star
40

CocoaVerbalExpression

Objective-C
2
star
41

buildly

Continuous build system for iOS apps
Python
2
star
42

sketchpreset

Useful sketch preset files
2
star
43

QLWebloc

This is a failed attempt to display the content of a webpage in quicklook from a .webloc file.
C
2
star
44

KGNUserInterface

A collection of the core user interface resources.
Swift
2
star
45

XCodeSnippets

CodeSnippets for Xcode + a python script to generate a readme so you can see what's in em
Python
2
star
46

pyglang

A python package for translating text with the 'Google AJAX Language API'
Python
2
star
47

KeeganScriptPack

A collection of mel scripts I wrote a while back.
2
star
48

CodingConventions

Name & Code Conventions for 1kLabs, Inc.
2
star
49

growlcoffee

Growl notifications for CoffeeScript
JavaScript
1
star
50

resume

My Resume
1
star
51

StyleGuide

The style guide for 1kLabs, Inc.
1
star
52

mdoc

GitHub markdown documentation generator for Objective-C
Python
1
star
53

PDFImageConverter

Modified code from a ipdfdev.com post
Objective-C
1
star
54

KGNSketchToolkit

Plugins for Sketch
JavaScript
1
star