2016-01-06 221 views
0

我正在从Parse载入图像并将图像加载到UITableViewCell中,我想根据检索到的图像的大小调整图像视图的大小。我怎样才能做到这一点?如果你需要一个例子,我认为Instagram的大小有不同的图像视图。如何根据图像大小调整图像视图大小?

+0

您可以更新自动布局约束编程的UIImageView的也可以是根据图像的尺寸以编程方式创建的UIImageView(添加为子视图)。 – nikhil84

回答

0

您可以通过使用自定义UITableViewCell调整图像查看,如果要实现自定义的电池我可以分享示例代码。

创建新的笔尖CustomCell和添加IBOutletUILabel(如果需要)和UIImageView

@interface CustomTableViewCell : UITableViewCell 
@property (nonatomic, retain) IBOutlet UILabel *nameLabel; 
@property (nonatomic, retain) IBOutlet UIImageView *thumbnailImageView; 
@end 

然后在课堂上,你回电池,不要使用自定单元

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString * simpleTableIdentifier = @"CustomTableViewCell"; 

    CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

    cell.nameLabel.text = @"If you want to set any text"; 
    [cell.thumbnailImageView setImage:[UIImage imageNamed:@"Replace Image Name"]]; 
    cell.thumbnailImageView.frame = CustomFrameYouWantToSet; 
    return cell; 
} 

您也可以参考以下实现自定义TableViewCell教程如下实施。
http://www.appcoda.com/customize-table-view-cells-for-uitableview/ http://code.tutsplus.com/tutorials/ios-sdk-crafting-custom-uitableview-cells--mobile-15702

+0

好的请说明一下。 – farhan

+0

@farhan我编辑了我的答案,希望我会对你有所帮助。 – Aamir