我的数据来自带有Html标记的服务器。
我希望将它显示在我的文本视图上,因为它的格式(粗体,字体等)。我该如何展示它?
Thanks in Advance
答案 0 :(得分:0)
NSString *infoString =@"I am iOS developer.";
NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:infoString];
UIFont *font_regular=[UIFont fontWithName:@"Helvetica" size:20.0f];
UIFont *font_bold=[UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
[attString addAttribute:NSFontAttributeName value:font_regular range:NSMakeRange(0, 4)];
[attString addAttribute:NSFontAttributeName value:font_bold range:NSMakeRange(5, 18)];
[self.txtView setAttributedText:attString];
答案 1 :(得分:0)
我使用Web View为此。创建一个对象并将该字符串加载到Web视图。 [_webView loadHTMLString:[strDescription description] baseURL:nil]; //将字符串设置为Web视图
增加Web视图的动态高度:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
CGRect frame = _webView.frame;
frame.size.height = 1;
_webView.frame = frame;
CGSize fittingSize = [_webView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
_webView.frame = frame;
[self.view layoutIfNeeded];
NSLog(@"size: %f, %f", fittingSize.width, fittingSize.height);
_bgScrollView.contentSize = CGSizeMake(320, fittingSize.height+370);
}