2 // UITableViewVibrantCell.swift
5 // Created by Jon Kent on 1/14/16.
11 open class UITableViewVibrantCell: UITableViewCell {
13 fileprivate var vibrancyView:UIVisualEffectView = UIVisualEffectView()
14 fileprivate var vibrancySelectedBackgroundView:UIVisualEffectView = UIVisualEffectView()
15 fileprivate var defaultSelectedBackgroundView:UIView?
16 open var blurEffectStyle: UIBlurEffectStyle? {
22 // For registering with UITableView without subclassing otherwise dequeuing instance of the cell causes an exception
23 public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
24 super.init(style: style, reuseIdentifier: reuseIdentifier)
27 required public init?(coder aDecoder: NSCoder) {
28 super.init(coder: aDecoder)
30 vibrancyView.frame = bounds
31 vibrancyView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
32 for view in subviews {
33 vibrancyView.contentView.addSubview(view)
35 addSubview(vibrancyView)
37 let blurSelectionEffect = UIBlurEffect(style: .light)
38 vibrancySelectedBackgroundView.effect = blurSelectionEffect
39 defaultSelectedBackgroundView = selectedBackgroundView
44 internal func updateBlur() {
45 // shouldn't be needed but backgroundColor is set to white on iPad:
46 backgroundColor = UIColor.clear
48 if let blurEffectStyle = blurEffectStyle, !UIAccessibilityIsReduceTransparencyEnabled() {
49 let blurEffect = UIBlurEffect(style: blurEffectStyle)
50 vibrancyView.effect = UIVibrancyEffect(blurEffect: blurEffect)
52 if selectedBackgroundView != nil && selectedBackgroundView != vibrancySelectedBackgroundView {
53 vibrancySelectedBackgroundView.contentView.addSubview(selectedBackgroundView!)
54 selectedBackgroundView = vibrancySelectedBackgroundView
57 vibrancyView.effect = nil
58 selectedBackgroundView = defaultSelectedBackgroundView