HTML String content for UILabel and TextView

馋奶兔 提交于 2019-11-30 16:11:24

问题


i got an object with contents of html markup in it, for example:

string = @"<p>This is wonderful</p> <p>Also some &#8216; entidies &#8217; <p>";

so i want first to convert this entidies in for my label text.

the second step would be to convert my p tags to line breaks.

the third step to convert my "img" tags to uiimageviews and some simple text formatting "b","strong" etc.

have you any ideas how to solve my problem?


回答1:


You should have a look at the Three20 project which includes a class TTStyledTextLabel which allows you to render HtmL-Code and even activates links.

TTStyledTextLabel  *htmlLabel = [[[TTStyledTextLabel alloc] initWithFrame:self.contentView.bounds] autorelease];
htmlLabel.userInteractionEnabled = YES;
[aView addSubview:htmlLabel];

htmlLabel.text = [TTStyledText textFromXHTML:htmlText];


来源:https://stackoverflow.com/questions/2261654/html-string-content-for-uilabel-and-textview

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