diff --git a/Pod/Classes/Objective-C/UIColor+Chameleon.h b/Pod/Classes/Objective-C/UIColor+Chameleon.h index 5e206f4..9a73439 100755 --- a/Pod/Classes/Objective-C/UIColor+Chameleon.h +++ b/Pod/Classes/Objective-C/UIColor+Chameleon.h @@ -57,7 +57,19 @@ typedef NS_ENUM (NSUInteger, UIGradientStyle) { * * @since 1.0 */ - UIGradientStyleTopToBottom + UIGradientStyleTopToBottom, + /** + * Returns a gradual blend between colors originating at the top left most point of an object's frame, and ending at the bottom right most point of the object's frame. + * + * @since 2.2.0 + */ + UIGradientStyleTopLeftToBottomRight, + /** + * Returns a gradual blend between colors originating at the top right most point of an object's frame, and ending at the bottom left most point of the object's frame. + * + * @since 2.2.0 + */ + UIGradientStyleTopRightToBottomLeft, }; /** diff --git a/Pod/Classes/Objective-C/UIColor+Chameleon.m b/Pod/Classes/Objective-C/UIColor+Chameleon.m index 1955674..aff8cba 100755 --- a/Pod/Classes/Objective-C/UIColor+Chameleon.m +++ b/Pod/Classes/Objective-C/UIColor+Chameleon.m @@ -539,6 +539,44 @@ + (UIColor *)colorWithGradientStyle:(UIGradientStyle)gradientStyle withFrame:(CG return [UIColor colorWithPatternImage:backgroundColorImage]; } + case UIGradientStyleTopLeftToBottomRight: { + + //Set out gradient's colors + backgroundGradientLayer.colors = cgColors; + + //Specify the direction our gradient will take + [backgroundGradientLayer setStartPoint:CGPointMake(0.0, 0.0)]; + [backgroundGradientLayer setEndPoint:CGPointMake(0.5, 1.0)]; + + //Convert our CALayer to a UIImage object + UIGraphicsBeginImageContextWithOptions(backgroundGradientLayer.bounds.size,NO, [UIScreen mainScreen].scale); + [backgroundGradientLayer renderInContext:UIGraphicsGetCurrentContext()]; + UIImage *backgroundColorImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + [self setGradientImage:backgroundColorImage]; + return [UIColor colorWithPatternImage:backgroundColorImage]; + } + + case UIGradientStyleTopRightToBottomLeft: { + + //Set out gradient's colors + backgroundGradientLayer.colors = cgColors; + + //Specify the direction our gradient will take + [backgroundGradientLayer setStartPoint:CGPointMake(1.0, 0.0)]; + [backgroundGradientLayer setEndPoint:CGPointMake(0.0, 1.0)]; + + //Convert our CALayer to a UIImage object + UIGraphicsBeginImageContextWithOptions(backgroundGradientLayer.bounds.size,NO, [UIScreen mainScreen].scale); + [backgroundGradientLayer renderInContext:UIGraphicsGetCurrentContext()]; + UIImage *backgroundColorImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + [self setGradientImage:backgroundColorImage]; + return [UIColor colorWithPatternImage:backgroundColorImage]; + } + case UIGradientStyleTopToBottom: default: { diff --git a/README.md b/README.md index 351efd5..b4d7a28 100644 --- a/README.md +++ b/README.md @@ -476,6 +476,8 @@ Chameleon provides three simple gradient styles. Gradients can be created from a **UIGradientStyles:** * `UIGradientStyleLeftToRight` (UIGradientStyle.LeftToRight in Swift) * `UIGradientStyleTopToBottom` (UIGradientStyle.TopToBottom in Swift) +* `UIGradientStyleTopLeftToBottomRight` (UIGradientStyle.TopLeftToBottomRight in Swift) +* `UIGradientStyleTopRightToBottomLeft` (UIGradientStyle.TopRightToBottomLeft in Swift) * `UIGradientStyleRadial` (UIGradientStyle.Radial in Swift) #####Normal Convention: