Microos
Microos

Reputation: 1768

About NSAttributes, How can I know what attributes there are

Toady, I wanted to change the TextField's placeholder's text colour programmatically. And I found a answer to fulfil it like this:

 let placeholder = NSAttributedString(string: "(\(i),\(j))", attributes: [NSForegroundColorAttributeName : UIColor.whiteColor()])
 tf.attributedPlaceholder = placeholder

When I successfully achieve my goal, I start considering that how can I know what properties dose a UIObject get, and what kind of NSAttribute should I use with some particular parameters.


For instance, I want to change the NavigationBar's title text Font and Color. The final solution is:

navigationController?.navigationBar.titleTextAttributes = 
        [
            NSForegroundColorAttributeName : UIColor.whiteColor(),
            NSFontAttributeName : UIFont(name: "Futura", size: 20)!
        ]

Do you see that there are two different Attributes. Firstly, they are quite similar to each other, but they are different. And they are also different from the first example.

That's really makes me confused!


So I am here to ask for some explanations, let me clear my self again:

1.How can I know are there any Attributes which can let me customise

2.If I already know there is any Attribute, how do I assign a proper Attribute-Object to it.

If anyone find that I am not clear enough, you can let me know, I will try my best to clear myself :D

thank you for your help!

Upvotes: 2

Views: 322

Answers (1)

Mats
Mats

Reputation: 8628

If I interpret your question correctly, you wish to find the documentation for all the attributes that can be set on an NSAttributedString.

You can find the page by alt-clicking (hold alt-key on keyboard and click) on NSForegroundColorAttributeName, and clicking on the reference link at the bottom.

Each Attribute name is described, as well as which type of object it expects.

It is also available at the page called NSAttributedString UIKit Additions from Apple, in the section named Character Attributes: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/NSAttributedString_UIKit_Additions/index.html#//apple_ref/doc/constant_group/Character_Attributes

Upvotes: 2

Related Questions