我正在从 Web 服务器下载 UITextView 内容,它只返回没有任何换行符的文本。我在要更改线路的地方插入 了\n
、\\n
、等,但这些都不起作用。[CR]
如何更改 UITextView 中文本的行?
问问题
1988 次
2 回答
0
奇怪的。为我工作。
_subtypeField = [[UITextView alloc] initWithFrame:CGRectMake(28, 189, self.bounds.size.width-30, 100)];
[_subtypeField setFont:[UIFont fontWithName:@"Helvetica" size:13]];
[_subtypeField setText:@"Examples:\n- Fentanyl\n- Dilaudid 2 mg PO q 4 hours prn moderate pain"];
[_subtypeField setTextAlignment:UITextAlignmentLeft];
[_subtypeField setTextColor:[UIColor colorWithRed:0.494 green:0.647 blue:0.808 alpha:1.0]];
[_subtypeField setOpaque:NO];
[_subtypeField setBackgroundColor:[UIColor clearColor]];
[_subtypeField setUserInteractionEnabled:NO];
[self addSubview:_subtypeField];
当您将 C 字符串转换为 NSString 时,可能会出现问题?换行符是否仍在 NSString 中?
于 2011-03-22T00:12:44.873 回答
0
如果您要显示的文本是动态的并且文本视图的宽度是固定的,那么您可以先根据文本计算文本视图的高度,然后在文本视图中显示该文本。这将自动更改文本视图中的行
我使用的代码:-
CGSize labelsize;
UITextView *commentsTextView = [[UITextView alloc] init];;
[commentsTextView setBackgroundColor:[UIColor clearColor]];
NSString *text=@"sample Text";//give your text
[commentsTextView setFont:[UIFont fontWithName:@"Helvetica"size:14]];
labelsize=[text sizeWithFont:commentsTextView.font constrainedToSize:CGSizeMake(268, 2000.0)];
commentsTextView.frame=CGRectMake(10, 24, 268, labelsize.height);
[self.view addSubview:commentsTextView];
[commentsTextView release];
于 2011-03-22T04:35:51.267 回答