而不是使用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