Skip to content

Instantly share code, notes, and snippets.

@SoCuul
Created May 12, 2026 02:20
Show Gist options
  • Select an option

  • Save SoCuul/042d27cfe51c5cf603279709924338ed to your computer and use it in GitHub Desktop.

Select an option

Save SoCuul/042d27cfe51c5cf603279709924338ed to your computer and use it in GitHub Desktop.
Load macOS Preference Pane into application
#import "AppDelegate.h"
#import "PreferencePanes/NSPreferencePane.h"
@interface AppDelegate ()
@property (strong) IBOutlet NSWindow *window;
@property (strong) NSPreferencePane *prefPaneObject;
@property (strong) NSView *prefView;
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSBundle *prefBundle = [NSBundle bundleWithPath: @"/System/Library/PreferencePanes/Appearance.prefPane"];
Class prefPaneClass = [prefBundle principalClass];
_prefPaneObject = [[prefPaneClass alloc] initWithBundle:prefBundle];
if ( [_prefPaneObject loadMainView] ) {
[_prefPaneObject willSelect];
_prefView = [_prefPaneObject mainView];
/* Add view to window */
[_prefPaneObject didSelect];
[_window.contentView addSubview:_prefView];
_window.contentMinSize = NSMakeSize(0, 0);
_window.contentMaxSize = NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX);
_window.styleMask |= NSWindowStyleMaskResizable;
NSView *contentView = self.window.contentView;
self.prefView = [self.prefPaneObject mainView];
self.prefView.translatesAutoresizingMaskIntoConstraints = NO;
[contentView addSubview:self.prefView];
[NSLayoutConstraint activateConstraints:@[
[self.prefView.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor],
[self.prefView.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor],
[self.prefView.topAnchor constraintEqualToAnchor:contentView.topAnchor],
[self.prefView.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor],
]];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment