BPKGradient

@interface BPKGradient : NSObject

The BPKGradient class contains definitions for the Backpack gradients. It has factory methods for creating instances of supported gradients. Instances of BPKGradient capture the configuration of the gradient, but are not concerned with rendering.

Warning

Don’t render Backpack gradients with CAGradientLayer as it does not accurately render gradients for non-square views. Instead use BPKGradientView which is backed by BPKGradientLayer.

See

BPKGradientView

  • The colors that define the gradient.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSArray<UIColor *> *_Nonnull colors;

    Swift

    var colors: [UIColor] { get }
  • The position of the stops defined as a number between 0 to 1 along the line created between the startPoint and endPoint.

    The number of stops will always match the number of colors for a given gradient. For stop n, the color at index n is used.

    See

    colors

    See

    startPoint

    See

    endPoint

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSArray<NSNumber *> *_Nonnull stops;

    Swift

    var stops: [NSNumber] { get }
  • The start point of the gradient in a (0, 1) range for x and y.

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGPoint startPoint;

    Swift

    var startPoint: CGPoint { get }
  • The end point of the gradient in a (0, 1) range for x and y.

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGPoint endPoint;

    Swift

    var endPoint: CGPoint { get }
  • Create a custom BPKGradient with specific colors, stops, startPoint and endPoint. The factory methods for defined Backpack gradients are preferred, but this init can be used for cases when they are not suitable.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithColors:(nonnull NSArray<UIColor *> *)colors
                                     stops:(nonnull NSArray<NSNumber *> *)stops
                                startPoint:(CGPoint)startPoint
                                  endPoint:(CGPoint)endPoint;

    Swift

    init(colors: [UIColor], stops: [NSNumber], start startPoint: CGPoint, end endPoint: CGPoint)

    Parameters

    colors

    The colors to use in the gradient.

    stops

    The locations to draw the corresponding color at, must have the same length as colors.

    startPoint

    The start point of the gradient.

    endPoint

    The end point of the gradient.

  • Create a custom BPKGradient with specific colors, startPoint and endPoint. The factory methods for defined Backpack gradients are preferred, but this init can be used for cases when they are not suitable. The stops are set to be evenly spaced along the line formed by the startPoint and endPoint.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithColors:(nonnull NSArray<UIColor *> *)colors
                                startPoint:(CGPoint)startPoint
                                  endPoint:(CGPoint)endPoint;

    Swift

    convenience init(colors: [UIColor], start startPoint: CGPoint, end endPoint: CGPoint)

    Parameters

    colors

    The colors to use in the gradient.

    startPoint

    The start point of the gradient.

    endPoint

    The end point of the gradient.

  • Create a new instance of the receiver with the same colors, but a new direction.

    Declaration

    Objective-C

    - (nonnull instancetype)cloneWithNewDirection:
        (BPKGradientDirection)newDirection;

    Swift

    func clone(withNewDirection newDirection: BPKGradientDirection) -> Self

    Parameters

    newDirection

    The direction of the new instance.

  • The Skyscanner primary gradient with the default direction.

    Declaration

    Objective-C

    + (nonnull instancetype)primary;

    Swift

    class func primary() -> Self

    Return Value

    The Skyscanner primary gradient.

  • The Skyscanner primary gradient with the direction specified.

    Declaration

    Objective-C

    + (nonnull instancetype)primaryWithDirection:(BPKGradientDirection)direction;

    Swift

    class func primary(direction: BPKGradientDirection) -> Self

    Parameters

    direction

    The desired direction.

    Return Value

    The Skyscanner primary gradient.

  • The Skyscanner baseline scrim gradient for use on images that contain text.

    The default direction is BPKGradientDirectionUp which is appropriate when the text content is at the bottom.

    Declaration

    Objective-C

    + (nonnull instancetype)baselineScrim;

    Swift

    class func baselineScrim() -> Self

    Return Value

    The default Skyscanner baseline scrim.

  • The Skyscanner baseline scrim gradient for use on images that contain text.

    Declaration

    Objective-C

    + (nonnull instancetype)baselineScrimWithDirection:
        (BPKGradientDirection)direction;

    Swift

    class func baselineScrim(direction: BPKGradientDirection) -> Self

    Parameters

    direction

    The desired direction. The text should be positioned near the start of the gradient.

    Return Value

    The default Skyscanner baseline scrim.

  • Calculate the start point for a given direction in the 0.0 to 1.0 inclusive range.

    Declaration

    Objective-C

    + (CGPoint)startPointForDirection:(BPKGradientDirection)direction;

    Swift

    class func startPoint(for direction: BPKGradientDirection) -> CGPoint

    Parameters

    direction

    A gradient direction

    Return Value

    Start point for the given direction as a CGPoint with values in the inclusive range 0.0 to 1.0.

  • Calculate the end point for a given direction in the 0.0 to 1.0 inclusive range.

    Declaration

    Objective-C

    + (CGPoint)endPointForDirection:(BPKGradientDirection)direction;

    Swift

    class func endPointFor(for direction: BPKGradientDirection) -> CGPoint

    Parameters

    direction

    A gradient direction

    Return Value

    End point for the given direction as a CGPoint with values in the inclusive range 0.0 to 1.0.