[英]How to increase the cell size with respect to the text size in detailTextLabel in iPhone.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
cell.detailTextLabel.numberOfLines = 0;
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
}
cell.textLabel.text = timelabel.text;
cell.detailTextLabel.text = commentTextView.text;
}
//int x = cell.commentTextView.frame.size.height;
}
cell.detailTextLabel.textAlignment = UITextAlignmentLeft;
cell.textLabel.textAlignment = UITextAlignmentLeft;
return cell;
}
我需要根據在文本視圖中輸入的注釋長度來擴展單元格大小:detailTextLabel中顯示'commentTextView'。
但是textLable(時間文本)的區別在於,它不會隨着detailTextLabel一起擴展
該怎么辦?
這一點總是很難做到,因為你需要實現這樣的高度。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *myLabel = "Hello World";
CGSize labelSize = [[myLabel sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(160,MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height;
}
您可以使用- (CGFloat)tableView:(UITableView *)t heightForRowAtIndexPath:(NSIndexPath *)indexPath
刪除方法的teble視圖,如: -
- (CGFloat)tableView:(UITableView *)t heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGSize lblSize ;
NSString *lblString ;
lblString = [[[dataSourceArray objectAtIndex:indexPath.row] valueForKey:@"aKey"];
lblSize = [self getLebalSize:CGSizeMake(180, 9999) aLebalText:lblString aFont:[UIFont systemFontOfSize:15]];
return lblSize.height + 10 ;
}
//getting labelsize
- (CGSize) getLebalSize : (CGSize) maxSize aLebalText : (NSString *) lebalText aFont : (UIFont *) font
{
CGSize expectedLabelSize = [lebalText sizeWithFont:font constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation];
return expectedLabelSize;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.