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];
I am trying allow users to copy and paste my text content that sits in a UITextView. I have some title text, which is bold, followed by regular, unbolded text. Any way to set up a UITextView such that a single select-all copy/paste will work on both bold title and non-bold content text?
Currently, I am adding another UITextView and styling it as bold but this requires 2 select/select-all copy/paste operations:
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用 UIWebView 并传入 HTML 字符串解决了这个问题,如下所示:
I solved this by using a UIWebView and passing in a HTML string like so: