emreoktem emreoktem - 2 months ago 33
Swift Question

NSTextField placeholderAttributedString Size Changes

I am developing a Cocoa app with Swift and using a NSTextField in order to let users to enter text.

I have also set a attributed placeholder string to this text field with following code:

MyTextField.placeholderAttributedString = NSAttributedString(string: "my placeholder text", attributes: [NSForegroundColorAttributeName:RGB(16, g: 105, b: 125, alpha: 0.5), NSFontNameAttribute:"Roboto-Medium", NSFontSizeAttribute:14])


and everything is fine about showing attributed placeholder string until I click on the text field.

When the user clicked on the field, the placeholder size changes to a smaller font by itself.

Any advices to avoid this will be appreciated...

Answer

Answering my own question.

The problem is solved when I set the attributed placeholder text as below.

MyTextField.placeholderAttributedString = NSAttributedString(string: "my placeholder text", attributes: [NSForegroundColorAttributeName:RGB(16, g: 105, b: 125, alpha: 0.5),NSFontAttributeName:NSFont(name: "Roboto-Medium", size: 14.0)!])

I hope it helps someone...

Comments