I currently developing an iOS APP that has a table whose cell contains an image. And I set the selected background view to an UIBlurEffectView, when the cell is selected, its text labels can normally show up but the image does not. Here is the screenshot before selection:
Here is the screenshot after selection:
Here is the codes setting the selected background view of cell:
let backgroundViewVisualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Light))
backgroundViewVisualEffectView.frame = cell.bounds
cell.selectedBackgroundView = backgroundViewVisualEffectView
Here is the codes adding the image to the cell:
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))
Why the image can not show up like text labels when I selecting the cell, any solutions?Thx
When the cell is selected it goes through subviews and makes the backgrounds clear so that the selection doesn't show artifacts. So, your issue is your test. Add an image to the image view and it should probably be fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.