3

I want to set 2 different fonts within the same UITextField and UITextView . How to do it?

Carina
  • 2,260
  • 2
  • 20
  • 45
  • I'm not sure I understand. Are you saying that you want to have 2 different fonts within the same textfield? Or are you asking how to change the font? – mkral Jul 20 '12 at 16:46

5 Answers5

5

Its a bit of work - you'll need to use Core Text and NSAttributedString to do this.

There are plenty of tutorials and examples, although I'd suggest using someone else's already-made UILabel subclass such as:

OHAttributedLabel

or

TTAttributedLabel

As these usually have some convenience methods to make handling a lot easier.

CrimsonDiego
  • 3,616
  • 1
  • 23
  • 26
1

I would do it with 2 custom textfields overlaying, both backgroundcolor:clearColor, maybe stuffed on an image that represents the background.

ott--
  • 5,642
  • 4
  • 24
  • 27
0

I don't think it is possible to handle 2 different fonts within the same UITextField or UITextView. If you want to have different font style you can either set different font style within a UIWebView or use the coreText API.

Here are some links that might help:

  1. iPhone Development - Setting UIWebView font
  2. the official doc on core text: https://developer.apple.com/library/mac/#documentation/StringsTextFonts/Conceptual/CoreText_Programming/Introduction/Introduction.html
Community
  • 1
  • 1
tiguero
  • 11,477
  • 5
  • 43
  • 61
0

I know you already picked a valid answer but... don't do it that way... it's not worth it. Use a webview instead and draw everything with html.

Radu Simionescu
  • 4,518
  • 1
  • 35
  • 34
0

In interface builder change Text View's Text field to Attributed. In that small editor that appears you can change the font/format/color of the selected text, like in any advanced text editor.

Radu Simionescu
  • 4,518
  • 1
  • 35
  • 34