How to get multiple text colors for a single NSTextField in Swift? -


textfield.stringvalue = "this part red - here blue" 

all inside 1 textfield in 2 different colors.

could put html code inside textfield? because want provide url link inside textfield, solve 2 problems.

look nsmutableattributedstring class achieve this.

example:

 attrstring = nsmutableattributedstring(string: "hello world", attributes: [nsfontattributename:uifont(name: "arial", size: 18.0)!])  attrstring.addattribute(nsforegroundcolorattributename, value: uicolor.redcolor(), range: nsrange(location:0,length:2)) 

this example creates nsmutableattributedstring , adds attribute sets string have red font color characters @ location 0 2.

documentation: https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/classes/nsmutableattributedstring_class/index.html


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -