0

NSTextFields을 약간 사용자 정의하려고 시도하고 있으며 첫 번째 단계는 placeholder을 사용자 정의하는 것입니다.AttributedString 자리 표시자를 설정할 때 NSTextField가 표시되지 않습니다.

나는 자리 표시 색상을 변경하려면, 나는이 방법으로 그것을 밖으로 시도하고있다 : 당신이 볼 수있는 바와 같이

- (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"]; 
} 

, 첫 NSTextField의 첫 번째 자리는 내가하려고 NSAttributedString에 의해 설립 색상을 지정합니다. 두 번째 NSTextField의 자리 표시자는 NSString입니다.

응용 프로그램을 실행하면 두 번째 NSTextField 만 표시됩니다. 처음에는 아무 것도 나타나지 않습니다.

현재 무슨 일입니까?

고맙습니다. 당신은 두 번 같은 emailTextField을 설정하는

답변

1

...

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

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

(즉 일을 수정하거나 문제가 단지 오류를했다합니까?)

+0

가 정확히, 그 점이었다. 고마워, 나는 그것을 보지 못했다. –