2016-09-07 13 views
0

這是我所得到的,當我後,我點擊細胞啓動我的應用程序我如何在tableview中保留圖片大小?

enter image description here

圖像變得更大

enter image description here

我的代碼是這樣的

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath) 


    // Configure the cell... 
    cell.imageView?.sd_setImageWithURL(NSURL(string: imageArray[indexPath.row]), placeholderImage:UIImage(named: "pin.png")) 

    cell.imageView?.frame = CGRectMake(0, 0, 50, 50) 
    return cell 
} 

imageArray只是一串圖片網址。請幫助

在此先感謝

+0

嘗試設置口罩,以邊界來的ImageView和Aspect填充圖像 – vishnuvarthan

+0

' cell.imageView?.clipsToBounds = true;'嘗試這個 – Shahrukh

+0

也嘗試用這個替換你的單元格 - 讓cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier(「myCell」,forIndexPath:indexPath)作爲UITableViewCell – vishnuvarthan

回答

1

你可以嘗試使用含量的不同模式屬性:

imageViewObject.contentMode = UIViewContentMode.ScaleToFill 

imageViewObject.contentMode = UIViewContentMode.ScaleAspectFit 

imageViewObject.contentMode = UIViewContentMode.ScaleAspectFill 
0

嘗試sd_setImageWithURL

cell.imageView?.sd_setImageWithURL(NSURL(string: "Your URL")!, placeholderImage: nil) { (image, error, cache, url) in 
    cell.imageView?.frame = CGRectMake(0, 0, 50, 50) 
} 

完成關閉這有助於設定框架。

+0

您可以使用[SDWebImage](https://github.com/rs/SDWebImage) – Shahrukh

+0

它不起作用 – rv7284

+1

然後,我會建議您創建自己的自定義單元格並設置它自己的限制。你可以參考這個教程,如果你喜歡http://www.apptuitions.com/uitableview-with-custom-cell-in-swift/ –

0

採取視圖必須更大尺寸則原始圖像視圖現在給backgruond顏色查看和該視圖中提供圖像視圖。它可能看起來像修復圖像的大小,但具有背景。

相關問題