[英]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.