HTML String content for UILabel and TextView

2019-02-11 03:02发布

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条回答
在下西门庆
2楼-- · 2019-02-11 03:55

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];
查看更多
登录 后发表回答