Swift UITextView with different formatting -
sorry basic question, i'm not sure start. following possible in swift?
in uitextview (not label, in possible duplicate), different bits of text having different formatting: instance, line of large text in same uitextview line of small text. here mockup of mean:
is possible in 1 uitextview?
you should have @ nsattributedstring
. here's example of how use it:
let largetextstring = "here large, bold text" let smalltextstring = "here smaller text" let textstring = "\n\(largetextstring)\n\n\(smalltextstring)" let attrtext = nsmutableattributedstring(string: textstring) let largefont = uifont(name: "arial-boldmt", size: 50.0)! let smallfont = uifont(name: "arial", size: 30.0)! // convert textstring nsstring because attrtext.addattribute takes nsrange. let largetextrange = (textstring nsstring).rangeofstring(largetextstring) let smalltextrange = (textstring nsstring).rangeofstring(smalltextstring) attrtext.addattribute(nsfontattributename, value: largefont, range: largetextrange) attrtext.addattribute(nsfontattributename, value: smallfont, range: smalltextrange) textview.attributedtext = attrtext
the result:
Comments
Post a Comment