2015-06-07 32 views
0

我目前正在開發一個iOS應用程序,該應用程序的表格的單元格包含圖像。 然後我將所選的背景視圖設置爲UIBlurEffectView,當選中單元格時,其文本標籤通常可以顯示,但圖像不顯示。 這裏是選擇之前的屏幕截圖: before selectioniOS UITableViewCell在單元問題上選擇背景視圖封面圖像

這裏是選擇後的屏幕截圖:

after selection

這裏是碼設定單元所選擇的背景視圖:

let backgroundViewVisualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Light)) 
backgroundViewVisualEffectView.frame = cell.bounds 
cell.selectedBackgroundView = backgroundViewVisualEffectView 

這裏是將圖像添加到單元格的代碼:

let contentImageView = UIImageView() 
contentImageView.backgroundColor = UIColor.whiteColor() 
cell.contentView.addSubview(contentImageView) 
contentImageView.setTranslatesAutoresizingMaskIntoConstraints(false) 
cell.contentView.addConstraint(NSLayoutConstraint(item: contentImageView, attribute: .CenterY, relatedBy: .Equal, toItem: cell.contentView, attribute: .CenterY, multiplier: 1, constant: 0)) 
cell.contentView.addConstraint(NSLayoutConstraint(item: contentImageView, attribute: .Trailing, relatedBy: .Equal, toItem: cell.contentView, attribute: .Trailing, multiplier: 1, constant: -cell.bounds.width/40)) 
contentImageView.addConstraint(NSLayoutConstraint(item: contentImageView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0, constant: 1.5 * cell.bounds.height)) 
contentImageView.addConstraint(NSLayoutConstraint(item: contentImageView, attribute: .Width, relatedBy: .Equal, toItem: contentImageView, attribute: .Height, multiplier: 1, constant: 0)) 

爲什麼圖像不能像文本標籤時,所選單元格它通過子視圖,使背景清楚,這樣的選擇不顯示顯示當我選擇單元格,任何解決方案?THX

+0

可以發佈代碼請 –

+0

圖片是什麼,爲什麼它只是白色? – Wain

+0

我還沒有真的加載圖像,只是把圖像視圖進行測試@Wain –

回答

1

文物。所以,你的問題就是你的考驗。添加一個圖像到圖像視圖,它應該很好。

+0

我剛試過!有用!謝謝 –