Class
DSButton
@IBDesignable public final class DSButton: UIButton
An Enterprise-styled push button element. It includes properties for adding and positioning Enterprise icons as well as all normal UIButton functionality.
For storyboards, add a UIButton to your view and change the class name to DSButton. BE SURE THE TYPE IS SET TO CUSTOM otherwise some colors won't show correctly.
Initialize and set properties as needed.
let button = DSButton(renderingType: .primary)
button.setTitle("Settings", for: .normal)
button.icon = .gear
The renderingType decides the behavior and appearance of the button. Enterprise Button is supported by primary, secondary and tertiary. For older Anatomy-style buttons, which appear as teal green, use the anatomyPrimary, anatomyDefault and anatomyTertiary rendering types.
If the button performs an asynchronous operation, you can present a spinning indicator by setting isLoading to true. (Anatomy button styles only.)
anatomyButton.isLoading = true
Relationships
Conforms To
UIButton
Initializers
init(renderingType:)
public init(renderingType: DSButtonRenderingType)
Initializes and returns a newly allocated DSButton with the specified renderingType.
Parameters
Name | Type | Description |
---|---|---|
renderingType | DSButtonRenderingType |
The renderingType to style DSButton. Can be changed after initialization as well. |
Properties
renderingType
public var renderingType: DSButtonRenderingType = .primary
The visual style of the button. Can be changed after initialization.
renderingTypeString
@IBInspectable public var renderingTypeString: String
The renderingType property representable by a String.
This property is only recommended for use in the Attributes inspector of a storyboard since enums are not @IBInspectable. Possible values are default, primary and tertiary. In code, use the renderingType property instead.
icon
public var icon: DSIconRenderingType?
An Enterprise icon to display next to the title. Can be positioned to the left or right of the title using imageLocation. Always displays as 24x24.
iconString
@IBInspectable public var iconString: String?
The icon property representable by a String.
This property is only recommended for use in the Attributes inspector of a storyboard since enums are not @IBInspectable. Possible values are left and right. In code, use the icon property instead.
imageLocation
public var imageLocation: DSButtonImageLocationType = .leading
Specifies which side of the title that the icon should display, left or right.
imageLocationString
@IBInspectable public var imageLocationString: String
The imageLocation property representable by a String.
This property is only recommended for use in the Attributes inspector of a storyboard since enums are not @IBInspectable. Possible values are left and right. In code, use the imageLocation property instead.
isHighlighted
public override var isHighlighted: Bool
Control is updated when highlighted status changes.
isLoading
public var isLoading: Bool = false
When set to true, the button contents disappear and are replaced by a spinning indicator. The button will also become disabled. Use this when you want to keep the user from tapping the button during an asynchronous activity for example.
buttonType
public override var buttonType: UIButton.ButtonType
accessibilityLabel
public override var accessibilityLabel: String?
intrinsicContentSize
public override var intrinsicContentSize: CGSize
Methods
setTitle(_:for:)
public override func setTitle(_ title: String?, for state: UIControl.State)
prepareForInterfaceBuilder()
public override func prepareForInterfaceBuilder()
awakeFromNib()
public override func awakeFromNib()
layoutSubviews()
public override func layoutSubviews()