【发布时间】:2016-08-31 07:09:01
【问题描述】:
我的问题是如何调整UITableViewCell 中的大文本和图像的固定大小。
根据 WhatsApp 等数据,我需要将单元格设为 autoresize。我该怎么做。
当我使用UILabel 时,我的单元格正在调整大小,但如果是图像,它会搞砸一切。
请给我建议。提前致谢。
@ddb 这是我正在使用的源代码。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [adminDataArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier=@"admincell";
adminCell =[tableView dequeueReusableCellWithIdentifier:identifier];
if (adminCell==nil) {
adminCell=[[AdminPostTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
adminCell.selectionStyle=UITableViewCellSelectionStyleNone;
[adminCell setBackgroundColor:[UIColor clearColor]];
NSMutableDictionary *getAdminDataDictionary=[adminDataArray objectAtIndex:indexPath.row];
if ([getAdminDataDictionary objectForKey:@"TEXT"])
{
adminCell.lblSenderAdminPage.text=[getAdminDataDictionary objectForKey:@"TEXT"];
adminCell.lblSenderAdminPage.textColor=[UIColor blackColor];
adminCell.lblSenderAdminPage.backgroundColor=[UIColor whiteColor];
adminCell.lblSenderAdminPage.preferredMaxLayoutWidth=305;
adminCell.lblSenderAdminPage.layer.masksToBounds=YES;
adminCell.lblSenderAdminPage.layer.cornerRadius=5;
adminCell.lblSenderAdminPage.layer.borderWidth=1.0f;
adminCell.lblSenderAdminPage.layer.borderColor=[UIColor blackColor].CGColor;
}
else if ([getAdminDataDictionary objectForKey:@"IMAGE"]){
adminCell.imgSenderAdminPage.image=[getAdminDataDictionary objectForKey:@"IMAGE"];
}
return adminCell;
}
【问题讨论】:
-
请分享您当前的源代码
标签: ios autoresize