0

I need to create one scrollable field which contains multiple fonts and images. Is that possible? I was thinking of using UITextView for this field, but I doubt that it can do what I need it to do.

reid55
  • 169
  • 3
  • 14

1 Answers1

0

If this field is not in a UITableView, then the easiest solution would be to organize your content in a html document then present it in a UIWebView which will work on both iOS5 and iOS6. Fonts can be handled through webfonts and styled via. css. Otherwise, you'll have some work to do.

You can learn about webfonts here:

https://developers.google.com/webfonts/docs/getting_started

For rich text in a UITextField ...

Well, there's good news and bad news. The good news is that it's pretty easy to do on iOS6. It's just a matter of creating an NSAttributedString and passing the string into a UITextView. The text should be formatted as you describe in an NSAttrbutedString.

If you haven't used an NSAttributedString, you can start learning about them over here:

How do you use NSAttributedString?

If you have an Apple developer account, check out the WWDC 2012 video: Introduction to Attributed Strings for iOS

https://developer.apple.com/videos/wwdc/2012/

Now the bad news ... this is not included in iOS5. So you have to a) build your own custom view using something like CoreText to render the text, b) punt and use a UIWebView (a terrible idea in a table view), or c) you can check out some of other home grown solutions such as these:

https://github.com/AliSoftware/OHAttributedLabel

https://github.com/enormego/EGOTextView#readme

There are more but you'll have to kick around google to find them.

As for images, it's just a matter of organizing the imageviews alongside the text views. Make sure to put all the content in a UIScrollView and you should be on your way.

Good luck!

Community
  • 1
  • 1
  • Thanks! It's not a table view, so I'll go with UIWebView. I've never used UIWebView for this sort of thing before. Do you happen to know of any examples or tutorials which will help me create the HTML and present it in the UIWebView? – reid55 Nov 03 '12 at 22:39
  • I thought I should also mention that my users will not necessarily have Internet access and text will be in Japanese, so I will need a couple of the Apple supported Japanese fonts. – reid55 Nov 03 '12 at 22:51