我有一個UITableViewCell
,它有一個UITextView
。當表加載每個UITextView
中的所有文本出現在一行中時。我使用白色文本顏色在IB
中創建了UITextView
。如何讓它以多行顯示,爲什麼文本顏色會切換爲黑色?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;
}
這裏是一個形象:
請嘗試添加:細胞layoutSubviews]恢復單元前 –
你有沒有實現的'的tableView:heightForRowAtIndexPath :'方法? – bobnoble
您能否提供包含textview的表格的屏幕截圖,即以正確和正確的方式。所以這會讓你的問題清楚,並會提供答案。否則你應該嘗試進行身高鍛鍊。 – nikhil84