繁体   English   中英

UITextView不能多行显示

[英]UITextView doesn't display in multiple lines

我有一个具有UITextViewUITableViewCell 当表加载时,每个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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM