开发者

How can I create a UITextView-based controller for showing html content

I am trying to develop an email-sending app which sends messages via custom API. The problem is that UITextView does not allow to display html content, and in order to forward/reply messages properly you sometimes need to edit an html-content that came from a previous message. However in a standard Mail.app on iPhone the UITextView or whatever they use there perfectly displays colored-text and links. My question is: is there any ready/half-ready component to recreate this behaviour, or at least any opinion on approach how to do that would be great. Thank you.

EDIT: MFMailComposeViewController does not fit the purpose of the application as it does not allow to control its behaviour and does not allow to send messages via custom API. TTMessageController from Three20开发者_JS百科 is what I use now, it allows to customize most stuff, except - the message body text view is just UITextView - and I can not put any html-content in there.


Three20's message controller is the closest you're going to get to a lookalike compose view.

Beyond that, you actually have two problems: autodetection of "live" content (links, phone numbers, etc) in text, and the rendering into a text view of arbitrary HTML.

For the former, UITextView has a dataDetectorTypes property on it. If you set that appropriately, you should get automatic detection of links, phone numbers, etc.

However this doesn't get you the latter. There's no trivial way I know of to convert HTML to an NSAttributedString, say, which would be how I would think of approaching it, and a totally cool project for someone to do. Maybe someone else has a resource on that.


That interface is ready for you to use. You can use it as a modal view, like this:

- (void)replyAction
{
    MFMailComposeViewController* mailController = [[MFMailComposeViewController alloc] init];
    mailController = self;
    [self presentModalViewController:mailController animated:YES];
    [mailController release];
}

You also need to import the MessageUI at your header file:

#import "MessageUI/MessageUI.h"

Set the inheritance:

YourClass <MFMailComposeViewControllerDelegate>

and add the MessageUI framework to your project. To do that, right click any group (like the Resources one) and choose Add -> Existing Frameworks... Then, look for MessageUI.framework. Add it and you're done.

Don't forget to check the official documentation for a lot of other options you can set for the MFMailComposeViewController.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜