而不是使用UITextView和RTF,您可以使用UIWebView和HTML(使用转换工具将RTF转换为HTML)。以下是如何将它全部挂起并更改文字大小。您可以随时致电resizeWebViewToSize
来调整文字大小。
- (void)viewDidLoad
{
[super viewDidLoad];
self.webView.delegate = self;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"HtmlFile" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:htmlString baseURL: [[NSBundle mainBundle] bundleURL]];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[self resizeWebViewToSize:@"1000"];
}
- (void)resizeWebViewToSize:(NSString *)size
{
NSString *fontSize=size;
NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'",[fontSize intValue]];
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
}
您是否尝试过使用webView代替textView? – Alex
@Alex你是一个向导! Sidepoint:Webview不能改变文本大小,文本对齐等。对吧? - 我知道你可以搜索标签...但RTF没有标签,因为它不是HTML的权利? – huddie96
我不知道你是否可以将RTF转换为html文档,然后添加格式?你应该能够将html元素作为文本添加到我想的rtf文本中。 – Alex