开发者

How to control the text color of an NSTextField when it is displaying a placeholder marker?

When the NSTextField (Label) is bound to a controller selection with bindings, and I have specified placeholder values for the Multiple Values Marker, No Selection Marker, etc it draws the text with 开发者_开发知识库a gray color that does not show up well on a dark background.

Is there a way to change the text color it uses to display the placeholder text?


Use an attributed string specifying the color you want, like this:

NSDictionary *blueDict = [NSDictionary dictionaryWithObject: [NSColor blueColor]
                        forKey: NSForegroundColorAttributeName];
NSAttributedString *blueString = [[[NSAttributedString alloc] initWithString: @"test"
                                attributes: blueDict] autorelease];

Then you can either set the placeholder attributed string directly:

[[field cell] setPlaceholderAttributedString: blueString];

or do it through a binding, for example:

[field2 bind: @"value" toObject: [NSUserDefaults standardUserDefaults]
        withKeyPath: @"foo"
        options: [NSDictionary dictionaryWithObject: blueString forKey: NSNullPlaceholderBindingOption]];


you can try to make your own "palceholder". I mean your can show a label over your textfield with any text patameters you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜