2016-01-06 304 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