0

I'm trying to customize a little bit my NSTextFields and the first step is to customize the placeholder.

I want to change the placeholder color, and I'm trying it out by this way:

- (void)awakeFromNib {

    // Color for placeholder in NSTextField - Color: #cdc9c1
    NSColor *placeholderColor = [NSColor colorWithCalibratedRed:0.80f green:0.78f blue:0.75f alpha:1.0f];

    NSDictionary *placeholderAttributeDict = [NSDictionary dictionaryWithObject:placeholderColor forKey:NSForegroundColorAttributeName];

    NSAttributedString *emailPlaceholderString = [[NSAttributedString alloc] initWithString:@"Email" attributes:placeholderAttributeDict];
    // NSAttributedString *passPlaceholderString = [[NSAttributedString alloc] initWithString:@"Password" attributes:placeholderAttributeDict];

   // NSTextField Email attributes
   [[self emailTextField] setDrawsBackground:NO];
   [[self emailTextField] setBordered:NO];
   [[[self emailTextField] cell] setPlaceholderAttributedString:emailPlaceholderString];

   // NSTextField Password attributes
   [[self passTextField] setDrawsBackground:NO];
   [[self passTextField] setBordered:NO];
   [[[self emailTextField] cell] setPlaceholderString:@"Password"];
}

As you may see, the first placeholder in the first NSTextField is established by an NSAttributedString where i try to specify color. The second placeholder in the second NSTextField is just a NSString.

When i run the application, it only shows the second NSTextField. First one doesn't appear anywhere.

What is happening?

Thanks in advanced.

Girish
  • 4,692
  • 4
  • 35
  • 55
Rubén Jiménez
  • 1,835
  • 5
  • 21
  • 29

1 Answers1

1

You are setting the same emailTextField twice...

[[[self emailTextField] cell] setPlaceholderAttributedString:emailPlaceholderString];

[[[self emailTextField] cell] setPlaceholderString:@"Password"];

(Does that fix things or was it just an error in the question?)

foundry
  • 31,615
  • 9
  • 90
  • 125