Display Rich Text Using a UIWebView
来源:互联网 发布:刷帖软件 编辑:程序博客网 时间:2024/06/08 19:10
A UITextView is great for displaying multiple lines of simple text. But when you need something more fancy, like headlines or highlighting text, then you should look at UIWebView. It’s not just capable of displaying web pages from a URL, but you can also specify the HTML you want to display as a string.
Create a UIWebView in a controller:
- - (void)loadView
- {
- // Create a custom view hierarchy.
- CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
- UIView *view = [[UIView alloc] initWithFrame:appFrame];
- view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
- self.view = view;
- [view release];
- CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
- webView = [[UIWebView alloc] initWithFrame:webFrame];
- webView.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:webView];
- }
Then you can add your rich text to the view like this:
- NSString *html = @"<html><head><title>The Meaning of Life</title></head><body><p>...really is <b>42</b>!</p></body></html>";
- [webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://www.hitchhiker.com/message"]];
The documentation is not very clear on what the baseURL is used for in the context of HTML that is loaded from a string.
- Display Rich Text Using a UIWebView
- Using UIWebView to display select document types
- 微信小程序 rich-text a标签
- [tfs] Using rich HTML descriptions instead of plain text
- Rich Text
- Rich Text
- Adding a Rich Text Editor to your Rails Application
- CRichEditControl50W - A VC++ Rich Text Edit 4.1 MFC Control
- display month as a calendar using sql
- display month as a calendar using sql
- echo - display a line of text
- TextView实现Rich Text
- Rich Text Processing
- 微信小程序 rich-text
- Can you refresh a document in the Notes client after changing a rich text field?
- Using .NET Databinding to Display Ink from a Database
- Using a modal .NET dialog to display AutoCAD object properties
- Using a modeless .NET dialog to display AutoCAD object properties
- IE6、7、8实现盒阴影
- (7,3)循环码编码译码
- UIView 圆角 边框
- Adobe将在今年年底为Android 4.0提供Flash支持
- Java语言中This关键字应用浅析
- Display Rich Text Using a UIWebView
- Mock使用的优势与陷阱(文章收集)
- 用Java实现按字节长度截取中英文数字字符串的方法总结
- C语言教程第九章:预处理
- Socket INADDR_ANY详解
- 获取手机唯一标识码
- 领导重视是不是好事?
- 关于limit hashlimit资料整理
- C语言教程第十章:文件