簡體   English   中英

UITableViewCell內部的動態UIlabel

[英]Dynamic UIlabel inside UITableViewCell

用戶可以發表評論,評論可以是任何大小或高度。 評論標簽的動態內容應適合單元格。

我已經在UITableViewCell內部分配了帶有鍵值的標簽。

cell.CommentLabel.text=[ResDiction objectForKey:@"Comment"];
cell.TimeLabel.text=[ResDiction objectForKey:@"CreateDate"];
cell.UserName.text=[ResDiction objectForKey:@"CreateUserName"];
cell.UserName.adjustsFontSizeToFitWidth=YES;
cell.CommentLabel.adjustsFontSizeToFitWidth=YES;
cell.CommentLabel.numberOfLines = 8;
cell.TimeLabel.adjustsFontSizeToFitWidth=YES;

如何讓標簽的內容確定像元高度?

你必須用

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableviwCell* cell=[tableview cellForRowAtIndexPath:indexPath];
cell.CommentLabel.text=[ResDiction objectForKey:@"Comment"];
cell.TimeLabel.text=[ResDiction objectForKey:@"CreateDate"];
cell.UserName.text=[ResDiction objectForKey:@"CreateUserName"];
cell.UserName.adjustsFontSizeToFitWidth=YES;
cell.CommentLabel.adjustsFontSizeToFitWidth=YES;
cell.CommentLabel.numberOfLines = 8;
cell.TimeLabel.adjustsFontSizeToFitWidth=YES;
float height= cell.cell.CommentLabel.frame.size.height+TimeLabel.frame.size.height+(all your UIFields you have used)

return height;
}

此方法將在創建單元格時返回其高度。 里面的代碼會計算每個uiField的高度並將它們組合起來,如果您像UITableview單元中的堆棧那樣排列,或者您必須根據您的排列來修改函數內部的代碼,這將起作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM