我有一個UILabel
。我想設置一個字符串,其中還包含一些HTML
標籤。該字符串是:如何在UILabel上顯示HTML字符串
NSString *str = @"<p>Hey you. My <b>name </b> is <h1> Joe </h1></p>";
我怎麼能在UILabel
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
mylabel.attributedText=attrStr;
上面的代碼並不顯示任何內容顯示這一點。
http://stackoverflow.com/questions/4789447/write-html-content-to-nsstring-and-display-on-iphone。希望對你有幫助。 – Meera
不顯示任何東西? 'attrStr'無?使用'error'參數怎麼樣?是'myLabel'零? – Larme
如果'UILabel'在你的情況下不起作用,那麼你爲什麼不使用爲它製作的'UIWebView'?只需禁用滾動。 – TheTiger