How to add Underline/Bold/Italicize Abilities for UITextView Swift [duplicate]

丶灬走出姿态 提交于 2019-11-28 11:52:07

问题


I have been searching for quite a while for a solution as to how to grant users the ability to underline, italicize and bold text in a UITextView but have not been able to find a solid solution. I have realized that I will need to use an NSAttributedString but am not sure as to how to create the UI and format the string so I am able to save it to a database. If you could point me in a proper direction that would be greatly appreciated. Thanks!


回答1:


The UI is simply an ordinary editable UITextView with allowsEditingTextAttributes set to true.

How you save is up to you, but the most universal solution is probably to pull out the UITextView's attributedText, archive it into an NSData (now known as Data in Swift), and save it off.



来源:https://stackoverflow.com/questions/41798358/how-to-add-underline-bold-italicize-abilities-for-uitextview-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!