Created
June 7, 2009 00:45
-
-
Save chandlerkent/125077 to your computer and use it in GitHub Desktop.
How to subclass CPTextField and customize behavior using becomeFirstResponder and assignFirstResponder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * AppController.j | |
| * NewApplication | |
| * | |
| * Created by You on May 21, 2009. | |
| * Copyright 2009, Your Company All rights reserved. | |
| */ | |
| @import <Foundation/CPObject.j> | |
| @implementation AppController : CPObject | |
| { | |
| } | |
| - (void)applicationDidFinishLaunching:(CPNotification)aNotification | |
| { | |
| var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], | |
| contentView = [theWindow contentView]; | |
| var label = [MyTextField textFieldWithStringValue:nil placeholder:@"PLACEHOLDER" width:300]; | |
| [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; | |
| [label setCenter:[contentView center]]; | |
| [contentView addSubview:label]; | |
| [theWindow orderFront:self]; | |
| // Uncomment the following line to turn on the standard menu bar. | |
| //[CPMenu setMenuBarVisible:YES]; | |
| } | |
| @end | |
| // Custom subclass of CPTextField | |
| @implementation MyTextField : CPTextField | |
| { | |
| } | |
| - (BOOL)becomeFirstResponder | |
| { | |
| [self setFont:[CPFont boldSystemFontOfSize:12.0]]; | |
| [super becomeFirstResponder]; | |
| return YES; | |
| } | |
| - (BOOL)resignFirstResponder | |
| { | |
| [self setFont:[CPFont systemFontOfSize:12.0]]; | |
| [super resignFirstResponder]; | |
| return YES; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment