iPhone - UITextField with rich text?

心已入冬 提交于 2019-12-04 17:18:42

Out of the box, you can only format a UITextField in its entirety.

There are some libraries that will help you display text using attributed strings but if you need editing capabilities you will have to pretty much write it all from the ground up using CoreText and UITextInput delegation.

From the research I've done, even the magnifying loupe and text selection controls will need to be recreated from scratch.

Have a look at the Omnigroup framework released on Github https://github.com/omnigroup and look for their Rich Text editor which will give you an idea of what's involved.

There's an alternative to this with the next iOS release and UIWebView but it cannot be discussed here as it is stil under NDA so you may want to head to the Apple forums if you need more info on it.

A UITextField has its own properties that can be set, such as font, textColor, textAlignment, and text. Icodeblogwrote up a great overview on everything that can be done with a UITextField here (including examples): http://www.icodeblog.com/2010/01/04/uitextfield-a-complete-api-overview/

So I haven't tried this, but what happens when you pass an NSAttributedString to UITextField? If this works then you could possibly add your own controls to do the editing of the attributed string. Possibly via an accessory view to the standard keyboard.

This also might help: https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML

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