Class
DSSwitchTableViewCell
@available(iOS 13.0, tvOS 13.0, *)
@IBDesignable public final class DSSwitchTableViewCell: UITableViewCell
A UITableViewCell that implements a UISwitch and label.
When enabled/disabled, the background color changes. In some situations, you may want this color to propagate to the superview automatically.
When added to a UITableView, this class lays out a DSSwitch while passing through the properties directly to it. It honors margins and exposes the underlying DSSwitch for further customization and data access.
For storyboards, add a UITableViewCell to your view and change the class name to DSSwitchTableViewCell.
Set a DSSwitchTableViewCellDelegate to the component to get notified about value changes.
Initialize and set properties as needed.
guard let cell = tableView.dequeue(...) as? DSSwitchTableViewCell else { return }
cell.title = "I agree to this policy"
cell.isOn = false
Note that in the storyboard the checkbox for Accessibility is unchecked, however, it will be enabled by default. Ignore the value of this checkbox. If you want to set this value to false, you must do so in code by setting isAccessibilityElement to false.
Set a DSSwitchTableViewCellDelegate to the component to get notified about value changes.
Relationships
Conforms To
UITableViewCell
Initializers
init?(coder:)
public required init?(coder: NSCoder)
init(style:reuseIdentifier:)
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?)
Properties
switchDelegate
@IBOutlet public weak var switchDelegate: DSSwitchTableViewCellDelegate?
The delegate which receives updates on the DSSwitchTableViewCell's state.
isEnabled
@IBInspectable public var isEnabled: Bool
Returns true if the switch is enabled and allows selection.