iPhone - UITextField with rich text?
Asked Answered
H

3

3

I want to allow bolding, italic ,underlines ,text-colors, etc in a UITextField.

Is there an external library that allows that? or am i suppose to write it myself?

Edit:

I want the user to be able to edit a portion of the text they way they want, let's say the first word would be bold, the second would be italic, and the third word would be normal

Hedve answered 26/6, 2011 at 23:2 Comment(0)
D
3

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.

Drainpipe answered 27/6, 2011 at 0:13 Comment(0)
H
0

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/

Heroworship answered 26/6, 2011 at 23:15 Comment(1)
I know that I want the user to be able to make a part of the text bold not the whole thingHedve
T
0

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

Tendance answered 26/6, 2011 at 23:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.