DSIcon

@IBDesignable
public final class DSIcon : UIImageView, DSIconDisplayable

An Anatomy-styled drop-in replacement for a UIImageView designed for (tinted) icon display. For storyboards, add a UIImageView to your view and change the class name to DSIcon.

Initialize with a rendering type to specify the image displayed. The default intrinsic size is 20x20, but can be overridden by specifying a renderingSize. A rendering size of .size24 would size the icon at 24x24. It’s recommended not to use layout constraints for sizing.

let defaultIcon = DSIcon(renderingType: .phone)
let smallIcon = DSIcon(renderingType: .credit_card, renderingSize: .size20)
let largeIcon = DSIcon(renderingType: .credit_card, renderingSize: .size24)

Do not attempt to change the icon directly using image as this change could be overwritten if other properties get changed:

let icon = DSIcon(renderingType: .phone)

icon.image = UIImage(named: "my-own-image-specified")
icon.renderingSize = .size20 // <-- improper Icon image will be lost

No tintColor is applied by DSIcon. The rendering type for a DSIcon can be changed at any time.

Accessors

  • The width and height of the icon. Icons are always square.

    Declaration

    Swift

    public var renderingSize: DSIconRenderingSize { get set }
  • The squared size of the icon 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 16, 24, and other sizes in IconRenderingSize. In code, use the renderingSize property instead.

    Declaration

    Swift

    @IBInspectable
    public var renderingSizeString: String { get set }
  • The image used by the icon. Can be changed after initialization.

    Declaration

    Swift

    public var renderingType: DSIconRenderingType { get set }
  • The image used by the icon 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 enumerations of IconRenderingType. In code, use the renderingType property instead.

    Declaration

    Swift

    @IBInspectable
    public var renderingTypeString: String { get set }
  • Returns the name of the rendering type

    Declaration

    Swift

    public var name: String { get }

Initializers

  • Initializes and returns a newly allocated DSIcon with the specified renderingType.

    Declaration

    Swift

    public init(renderingType: DSIconRenderingType)

    Parameters

    renderingType

    The renderingType to style the component.

  • Initializes and returns a newly allocated Icon with the specified renderingType.

    Declaration

    Swift

    public init(renderingType: DSIconRenderingType, renderingSize: DSIconRenderingSize)

    Parameters

    renderingType

    The renderingType to style the component.

    renderingSize

    The renderingSize to style the component.