你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> ios 動態設置Cell的高度

ios 動態設置Cell的高度

編輯:IOS開發綜合

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

self.mainTitle=[[UILabel alloc]init];
self.mainTitle.numberOfLines=0;
self.mainTitle.font=[UIFont fontWithName:@"Hiragino Sans GB" size:14];
self.mainTitle.text=cell_info.title;
self.mainTitle.textColor=[UIColor grayColor];
CGSize titleSize=[self.mainTitle.text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width-20, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: self.mainTitle.font} context:nil].size;
self.rowHeight=titleSize.height;
self.mainTitle.frame=CGRectMake(15, 3, titleSize.width,titleSize.height);
[cell.contentView addSubview:self.mainTitle];

CGRect cellFrame=[cell frame];
cellFrame.origin=CGPointMake(0,0);
cellFrame.size.height=self.mainTitle.frame.size.height+5+self.imgOne.frame.size.height+5;
[cell setFrame:cellFrame];

return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0) {
return 160;
}
else{
// if (indexPath.row==0) {
// UITableViewCell *cell=[self tableView:self.tableView cellForRowAtIndexPath:indexPath];
// return cell.frame.size.height;
// }
UITableViewCell *cell=[self tableView:self.tableView cellForRowAtIndexPath:indexPath];
return cell.frame.size.height;
}
}

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved