-
-
Save jaigouk/206081 to your computer and use it in GitHub Desktop.
This file contains 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 | |
* textfield | |
* | |
* Created by You on October 9, 2009. | |
* Copyright 2009, Your Company All rights reserved. | |
*/ | |
@import <Foundation/CPObject.j> | |
@import "MyTextField.j" | |
@implementation AppController : CPObject | |
{ | |
CPTextField label; | |
CPString defaultValue; | |
} | |
- (void)applicationDidFinishLaunching:(CPNotification)aNotification | |
{ | |
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], | |
contentView = [theWindow contentView]; | |
defaultValue = @"Hello World!"; | |
label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()]; | |
[label setStringValue: defaultValue]; | |
[label setFrameSize: CGSizeMake(370, 40)]; | |
[label setFrameOrigin: CGPointMake(10, 10)]; | |
[label setFont: [CPFont boldSystemFontOfSize: 20.0]]; | |
[label setTextColor:[CPColor colorWithHexString: @"000000"]]; | |
[label setBezeled: YES]; | |
[label setDelegate: self]; | |
[label setEditable: YES]; | |
[contentView addSubview:label]; | |
label2 = [[MyTextField alloc] initWithFrame:CGRectMakeZero()]; | |
var defaultValue2 = @"Good Night!"; | |
[label2 setStringValue: defaultValue2]; | |
[label2 setDefaultValue: defaultValue2]; | |
[label2 setFrameSize: CGSizeMake(370, 40)]; | |
[label2 setFrameOrigin: CGPointMake(10, 50)]; | |
[label2 setFont: [CPFont boldSystemFontOfSize: 20.0]]; | |
[label2 setTextColor:[CPColor colorWithHexString: @"000000"]]; | |
[label2 setBezeled: YES]; | |
[label2 setEditable: YES]; | |
[contentView addSubview:label2]; | |
[theWindow orderFront:self]; | |
} | |
// SetPlaceHolderString Works When using delegate | |
-(void) controlTextDidBeginEditing: (CPNotification) aNote | |
{ | |
if([label stringValue] == defaultValue){ | |
[label setPlaceholderString: ""]; | |
} | |
} | |
-(void) controlTextDidEndEditing: (CPNotification) aNote | |
{ | |
if([label stringValue] == ""){ | |
[label setPlaceholderString: defaultValue]; | |
} | |
} | |
@end |
This file contains 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
/** | |
* MyTextField.j | |
*/ | |
@implementation MyTextField : CPTextField | |
{ | |
CPString _defaultValue; | |
} | |
- (void) setDefaultValue: (CPString) anDefaultValue | |
{ | |
_defaultValue = anDefaultValue; | |
} | |
- (CPString) defaultValue | |
{ | |
return _defaultValue; | |
} | |
// SetPlaceHolderString Does not Work when subclassing in the textDidBeginEditing method. | |
-(void) textDidBeginEditing: (CPNotification) aNote | |
{ | |
if([self stringValue] == [self defaultValue]){ | |
console.log("value before >> " + [self defaultValue]); | |
[self setPlaceholderString: ""]; | |
console.log("value after >> " + [self defaultValue]); | |
} | |
} | |
-(void) textDidEndEditing: (CPNotification) aNote | |
{ | |
if([self stringValue] == ""){ | |
[self setPlaceholderString: [self defaultValue]]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment