Skip to content

Instantly share code, notes, and snippets.

@mhpavl
Created November 20, 2015 14:35
Show Gist options
  • Save mhpavl/f7819743027684b9e890 to your computer and use it in GitHub Desktop.
Save mhpavl/f7819743027684b9e890 to your computer and use it in GitHub Desktop.
tvOS Settings-style table view cell
class SettingCell: UITableViewCell {
@IBOutlet var customTextLabel: UILabel!
@IBOutlet var customDetailTextLabel: UILabel!
private let unfocusedBackgroundColor: UIColor? = UIColor(white: 1, alpha: 0.2)
override func awakeFromNib() {
super.awakeFromNib()
backgroundColor = unfocusedBackgroundColor
layer.cornerRadius = 5
layer.masksToBounds = true
}
override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
super.didUpdateFocusInContext(context, withAnimationCoordinator: coordinator)
coordinator.addCoordinatedAnimations({
self.backgroundColor = self.focused ? UIColor.clearColor() : self.unfocusedBackgroundColor
self.layer.masksToBounds = !self.focused
}, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment