2013-01-25 30 views
1

對於我的應用程序的聯繫人視圖,我在表格視圖中添加了基於他的電子郵件ID的個人用戶圖像。由於每個用戶的圖像大小不同,圖像視圖對於所有用戶都不是唯一的,有些圖像視圖的寬度更多,因此我將UItableViewCell的框架大小設置爲固定寬度,但寬度大小也不相同。如何爲UITableViewCell的ImageView設置固定大小?

[cell.imageView setFrame:CGRectMake(0, 0, 55, 55)]; 

我該怎麼辦?我是否需要添加新的圖像視圖作爲細胞的子視圖?任何想法?

+0

你繼承你的tableviewcell ...按照這個http://stackoverflow.com/questions/2788028/how-do-i-make-uitableviewcells-imageview-a-fixed-size-even-when-the-image-is-sm – user523234

回答

1

你應該設置你的imageview的屬性,以顯示不同大小的不同圖像。

例如,

<imageview_name>.contentMode = UIViewContentModeScaleAspectFit; 

欣賞節目!

2

UITableView的imageView屬性是隻讀的。在設置到單元格的imageView之前,您可以調整圖像大小。要調整圖像大小,您可以從StackOverflow answer獲得幫助。另外,如果你從Web環境加載你的圖片,你可以使用我的AFNetworking分支,我在UIImageView擴展中添加了圖片大小調整選項。 https://github.com/polatolu/AFNetworking

0

子類UITableViewCell並覆蓋此方法;

- (void)layoutSubviews { 

    [super layoutSubviews]; 

    self.imageView.frame = CGRectMake(0,0,55,55); 

    //Any additional setting that you want to do with image view 

    [self.imageView setAutoresizingMask:UIViewAutoresizingNone]; 

} 
+2

這確實修復圖像大小,但不幸的是文字標籤不會移動位置以符合新的圖像尺寸 – Wizfinger

0

我使用的是同一個JSON文件,以填補一個UITableView,這裏是我使用的是什麼在CustomCell一個通用的應用程序:

- (void)layoutSubviews { 
    [super layoutSubviews]; 
    if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad) { 
     self.imageView.frame = CGRectMake(0,0,300,100); 

    }else if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){ 
     self.imageView.frame = CGRectMake(0,0,180,60); 
    } 
    float limgW = self.imageView.image.size.width; 
    if(limgW > 0) { 

     if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad) { 
      self.textLabel.frame = CGRectMake(320,self.textLabel.frame.origin.y,self.textLabel.frame.size.width,self.textLabel.frame.size.height); 

     }else if (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){ 
      self.textLabel.frame = CGRectMake(182,self.textLabel.frame.origin.y,self.textLabel.frame.size.width,self.textLabel.frame.size.height); 
     } 

    } 
} 
相關問題