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
startPointandendPoint.The number of stops will always match the number of colors for a given gradient. For stop
n, the color at indexnis used.See
colorsSee
startPointSee
endPointDeclaration
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
BPKGradientwith specificcolors,stops,startPointandendPoint. 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
colorsThe colors to use in the gradient.
stopsThe locations to draw the corresponding color at, must have the same length as
colors.startPointThe start point of the gradient.
endPointThe end point of the gradient.
-
Create a custom
BPKGradientwith specificcolors,startPointandendPoint. The factory methods for defined Backpack gradients are preferred, but this init can be used for cases when they are not suitable. Thestopsare set to be evenly spaced along the line formed by thestartPointandendPoint.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
colorsThe colors to use in the gradient.
startPointThe start point of the gradient.
endPointThe 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) -> SelfParameters
newDirectionThe direction of the new instance.
-
The Skyscanner primary gradient with the default direction.
Declaration
Objective-C
+ (nonnull instancetype)primary;Swift
class func primary() -> SelfReturn 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) -> SelfParameters
directionThe desired direction.
Return Value
The Skyscanner primary gradient.
-
The Skyscanner baseline scrim gradient for use on images that contain text.
The default direction is
BPKGradientDirectionUpwhich is appropriate when the text content is at the bottom.Declaration
Objective-C
+ (nonnull instancetype)baselineScrim;Swift
class func baselineScrim() -> SelfReturn 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) -> SelfParameters
directionThe 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) -> CGPointParameters
directionA gradient direction
Return Value
Start point for the given direction as a
CGPointwith 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) -> CGPointParameters
directionA gradient direction
Return Value
End point for the given direction as a
CGPointwith values in the inclusive range 0.0 to 1.0.
BPKGradient Class Reference