Thursday, January 24, 2013

Controlling basic window actions without a toolbar.

Controlling Window Actions on OS X without a toolbar/topbar

First of all, I know it's been awhile since I have posted. I have been so busy with projects and Firefox bugs, I have had very little time to write. However, I am back now.

One day a thought came to me, on OS X apps, we always have the titlebar, the thing that holds the red, orange, and green buttons, plus the title. Well, it's kind of useless isn't it? It is. It can only do three (Maybe four) things. Close the window. Minimize the window, or zoom it. Well, I decided that I could do that myself, as well as add other things. So I did.

The first step is to head to your xib file and uncheck the button on the window about having the titlebar. Now, when you do that, all controls up there will be gone, and you might wonder how to preform basic functions, well it is quite easy.

Check drag three buttons to wherever you want, making sure to have them aligned to the top. Also, make sure you have your NSWindow defined, as you will need to call that. Once you do that, attach three IBActions, each action should do the following:

In the .h

#import <Cocoa/Cocoa.h>

@interface TitleAppAppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;


Then, in the .m

#import "TitleAppAppDelegate.h"

@implementation TitleAppAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    // Insert code here to initialize your application
    [window orderFront:window];

- (IBAction)closeSecondWindow:(id)sender {
    [window close];

-(IBAction)minimizeWindow:(id)sender {
    [window miniaturize:window];

-(IBAction)zoomWindow:(id)sender {
    [window zoom:window];
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
    return YES;  //Note that this whole method is optional.

Hard huh? Not at all. This is extremely easy to do, and allows all kinds of customization options. I suggest everyone at least try it. The real key is finding (Or making) some images that you can use for your buttons.

Have fun!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.