UIColor(HBAdditions)

@interface UIColor (HBAdditions)

UIColor (HBAdditions) is a class category in Cephei that provides some convenience methods.

  • Creates and returns a color object using data from the specified object.

    The value is expected to be one of the types specified in hb_initWithPropertyListValue:.

    See

    hb_initWithPropertyListValue:

    Declaration

    Objective-C

    + (nonnull instancetype)hb_colorWithPropertyListValue:(nonnull id)value;

    Swift

    convenience init(propertyListValue value: Any)

    Parameters

    value

    The object to retrieve data from. See the discussion for the supported object types.

    Return Value

    The color object. The color information represented by this object is in the device RGB colorspace.

  • Initializes and returns a color object using data from the specified object.

    The value is expected to be one of:

    • An array of 3 or 4 integer RGB or RGBA color components, with values between 0 and 255 (e.g. @[ 218, 192, 222 ])
    • A CSS-style hex string, with an optional alpha component (e.g. #DAC0DE or #DACODE55)
    • A short CSS-style hex string, with an optional alpha component (e.g. #DC0 or #DC05)

    Declaration

    Objective-C

    - (nonnull instancetype)hb_initWithPropertyListValue:(nonnull id)value;

    Parameters

    value

    The object to retrieve data from. See the discussion for the supported object types.

    Return Value

    An initialized color object. The color information represented by this object is in the device RGB colorspace.

  • Initializes and returns a dynamic color object using the provided interface style variants.

    This color dynamically changes based on the interface style on iOS 13 and newer. If dynamic colors are not supported by the operating system, the value for UIUserInterfaceStyleLight or UIUserInterfaceStyleUnspecified is returned.

    Example:

    UIColor *myColor = [UIColor hb_colorWithInterfaceStyleVariants:@{
        @(UIUserInterfaceStyleLight): [UIColor systemRedColor],
        @(UIUserInterfaceStyleDark): [UIColor systemOrangeColor]
    }];
    

    Declaration

    Objective-C

    + (nonnull instancetype)hb_colorWithInterfaceStyleVariants:
        (nonnull NSDictionary<NSNumber *, UIColor *> *)variants;

    Swift

    class func hb_color(withInterfaceStyleVariants variants: [NSNumber : UIColor]) -> Self

    Parameters

    variants

    A dictionary of interface style keys and UIColor values.

    Return Value

    An initialized dynamic color object, or the receiver if dynamic colors are unsupported by the current operating system.

  • Initializes and returns a dynamic color object, with saturation decreased by 4% in the dark interface style.

    See

    +[UIColor hb_colorWithInterfaceStyleVariants:]

    Declaration

    Objective-C

    - (nonnull instancetype)hb_colorWithDarkInterfaceVariant;

    Swift

    func withDarkInterfaceVariant() -> Self

    Return Value

    If the color is already a dynamic color, returns the receiver. Otherwise, a new dynamic color object.

  • Initializes and returns a dynamic color object, with the specified variant color for the dark interface style.

    Example:

    UIColor *myColor = [[UIColor systemRedColor] hb_colorWithDarkInterfaceVariant:[UIColor systemOrangeColor]];
    

    See

    +[UIColor hb_colorWithInterfaceStyleVariants:]

    Declaration

    Objective-C

    - (nonnull instancetype)hb_colorWithDarkInterfaceVariant:
        (nonnull UIColor *)darkColor;

    Swift

    func withDarkInterfaceVariant(_ darkColor: UIColor) -> Self

    Parameters

    darkColor

    The color to use in the dark interface style.

    Return Value

    A new dynamic color object.