2012-02-08 70 views
1

我想讓用戶複製並粘貼位於UITextView中的文本內容。我有一些粗體的標題文字,後面是常規的未開啓文字。任何設置UITextView的方式,使得單個全選複製/粘貼可以同時用於粗體標題和非粗體內容文本?UITextView中的簡單文本格式

目前,我加入了另外的UITextView和其樣式,大膽,但這需要2選擇/全選複製/粘貼操作:

txtView = [[UITextView alloc] initWithFrame:CGRectMake(0,60,280,300)]; 
[txtView setFont:[UIFont fontWithName:@"ArialMT" size:14]]; 




txtView.text = word.definition; 


txtView.editable = NO; 
txtView.scrollEnabled = YES; 
[txtView scrollRangeToVisible:NSMakeRange([txtView.text length], 0)]; 
txtView.minimumZoomScale = 1; 
txtView.maximumZoomScale = 10; 

UITextView *wordTitle = [[UITextView alloc] initWithFrame:CGRectMake(0, 10, 320, 50)]; 

[wordTitle setFont:[UIFont boldSystemFontOfSize:14]]; 
wordTitle.text = word.term; 
wordTitle.textAlignment = UITextAlignmentCenter; 



[detailsViewController.view addSubview:wordTitle]; 
[detailsViewController.view addSubview:txtView]; 

[txtView release]; 
txtView = nil; 

[htmlView release]; 
htmlView = nil; 

[scrollView release]; 
scrollView = nil; 


[[self navigationController] pushViewController:detailsViewController animated:YES]; 
[detailsViewController release]; 

回答

0

我解決了這個使用一個UIWebView並傳入HTML字符串像這樣:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    //...more code here 

    NSString *htmlDefinition = [word.definition stringByReplacingOccurrencesOfString:@"\n" 
                    withString:@"<br />"]; 

    NSString *htmlString = [NSString stringWithFormat:@"<h2>%@</h2><p>%@</p>",[word term],htmlDefinition]; 

    [htmlView loadHTMLString:htmlString baseURL:nil]; 

    scrollView.contentSize = [htmlView bounds].size; 

    [scrollView addSubview:htmlView]; 

    [detailsViewController.view addSubview:htmlView]; 
    [htmlView release]; 
    htmlView = nil; 


}