我的問題是如何調整UITableViewCell
中的大圖像和固定大小的圖像。
根據像WhatsApp等數據,我需要單元格爲autoresize
。我該怎麼做。 當我使用UILabel
時,我的單元格正在調整大小,但是在圖像的情況下會將所有內容搞亂。根據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 *[email protected]"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;
}
分享自己當前的源代碼,請 – ddb
試試這個鏈接http://stackoverflow.com/a/14841373/4970453 –