[英]UITextView doesn't display in multiple lines
I have a UITableViewCell
that has a UITextView
. 我有一个具有
UITextView
的UITableViewCell
。 When the table loads all of the text in each UITextView
appears in a single line. 当表加载时,每个
UITextView
中的所有文本都显示在一行中。 I created the UITextView
in IB
with a white text color. 我在
IB
使用白色文本颜色创建了UITextView
。 How do I get it to display in multiple lines, and why did the text color switch to black? 如何使其显示为多行,为什么文本颜色切换为黑色?
The height of each UITableViewCell
is correct. 每个
UITableViewCell
的高度是正确的。 It used to display the text in multiple lines after I refreshed the table by pulling down, but for some reason that stopped working too. 在我通过下拉刷新表格后,它通常以多行显示文本,但是由于某些原因,它也停止了工作。
If there's any other information you require, please let me know. 如果您需要其他任何信息,请告诉我。
Here's the relevant code: 以下是相关代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
BIDChatCell *cell = (BIDChatCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[BIDChatCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell
cell.backgroundColor = [UIColor clearColor];
cell.userLabel.text = [object objectForKey:@"username"];
NSString *time = [object objectForKey:@"time"];
NSString *date = [time substringToIndex:10];
cell.timeLabel.text = date;
NSString *chatText = [object objectForKey:@"text"];
UIFont *font = [UIFont systemFontOfSize:14];
CGSize size = [chatText sizeWithFont:font constrainedToSize:CGSizeMake(200.0f, 1000.0f) lineBreakMode:UILineBreakModeCharacterWrap];
cell.textStringView.frame = CGRectMake(75, 15, size.width +20, size.height + 20);
cell.textStringView.font = [UIFont fontWithName:@"Helvetica" size:14.0];
cell.textStringView.text = chatText;
[cell.textStringView sizeToFit];
[cell.textStringView.textContainer setSize:cell.textStringView.frame.size];
CGRect frame = cell.textStringView.frame;
frame.size.height = cell.textStringView.contentSize.height;
cell.textStringView.frame = frame;
[cell layoutSubviews];
return cell;
} }
Here's an image: 这是一张图片:
Try setting the height of the textView like so: 尝试像这样设置textView的高度:
CGRect frame = cell.textStringView.frame;
frame.size.height = cell.textStringView.contentSize.height;
cell.textStringView.frame = frame;
Does the UITextView have the proper autoresizingMask
? UITextView是否具有适当的
autoresizingMask
吗?
It likely needs it set to (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)
to allow the textview to grow (as it normally uses a UIScrollView instead) 它可能需要将其设置为
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)
以允许textview增长(因为它通常使用UIScrollView代替)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.