osx - change the color and the font of NStextView -


i trying change color , font size of nstextview doesn't seem work.this code.i have checked other posts dont seem working.this code.

 var area:nsrange = nsmakerange(0, textview.textstorage!.length)  self.textview.settextcolor(nscolor.graycolor(), range: area)  self.textview.textstorage?.font = nsfont(name: "calibri", size: 16) 

you should use attributed strings:

let textview = nstextview(frame: nsmakerect(0, 0, 100, 100)) let attributes = [nsforegroundcolorattributename: nscolor.redcolor(),                   nsbackgroundcolorattributename: nscolor.blackcolor()] let attrstr = nsmutableattributedstring(string: "my string", attributes: attributes) let area = nsmakerange(0, attrstr.length) if let font = nsfont(name: "helvetica neue light", size: 16) {     attrstr.addattribute(nsfontattributename, value: font, range: area)     textview.textstorage?.appendattributedstring(attrstr) } 

playground


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -