[英]UITextView doesn't display in multiple lines
我有一个具有UITextView
的UITableViewCell
。 当表加载时,每个UITextView
中的所有文本都显示在一行中。 我在IB
使用白色文本颜色创建了UITextView
。 如何使其显示为多行,为什么文本颜色切换为黑色?
每个UITableViewCell
的高度是正确的。 在我通过下拉刷新表格后,它通常以多行显示文本,但是由于某些原因,它也停止了工作。
如果您需要其他任何信息,请告诉我。
以下是相关代码:
- (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;
}
这是一张图片:
尝试像这样设置textView的高度:
CGRect frame = cell.textStringView.frame;
frame.size.height = cell.textStringView.contentSize.height;
cell.textStringView.frame = frame;
UITextView是否具有适当的autoresizingMask
吗?
它可能需要将其设置为(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)
以允许textview增长(因为它通常使用UIScrollView代替)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.