• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Duplicating Apple search field UI
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Duplicating Apple search field UI


  • Subject: RE: Duplicating Apple search field UI
  • From: Francisco Tolmasky <email@hidden>
  • Date: Sat, 12 Apr 2003 02:22:45 -0700

Ok, so I got the source code for that apple search UI dealie, and it
appears the creator is having some trouble with the gray text.

I was able to solve this same problem in my own code by doing about 2
hours worth of searching through the docs.

The problem is, once the text field receives first responder status, it
immediately resigns it to the internal nstext class.

Here was my clever way of getting around it (this version IS foolproof,
there is no problem with clicking in the text field, then clicking
away, and the text going away. It is 100% working to the best of my
knowledge):

@implementation TPSearchTextField

- (id)initWithCoder:(NSCoder *)aCoder
{
self= [super initWithCoder: aCoder];
if(self)
{
[self setTextColor: [NSColor grayColor]];
[self setStringValue: @"Search"];
_keyEntered= NO;
}
return self;
}

- (BOOL)becomeFirstResponder
{
BOOL become= [super becomeFirstResponder];
if(become && !_keyEntered)
{
[self setStringValue: @""];
[self setTextColor: [NSColor blackColor]];
}
return become;
}

- (void)textDidEndEditing:(NSNotification *)aNotification
{
[super textDidEndEditing: aNotification];
if([[self stringValue] isEqualToString: @""])
{
[self setTextColor: [NSColor grayColor]];
[self setStringValue: @"Search"];
_keyEntered= NO;
}
}

- (void)textDidChange:(NSNotification *)aNotification
{
_keyEntered= YES;
[super textDidChange: aNotification];
}

Francisco Tolmasky
email@hidden
http://users.adelphia.net/~ftolmasky
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: [OT?] Nib files balloon app size
  • Next by Date: Open/Save Dialogs Questions
  • Previous by thread: Make the action of a NSMenuItem, which has a subMenu, to work
  • Next by thread: Open/Save Dialogs Questions
  • Index(es):
    • Date
    • Thread