Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Created new UIGrandientStyles #177

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Pod/Classes/Objective-C/UIColor+Chameleon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

/**
Expand Down
38 changes: 38 additions & 0 deletions Pod/Classes/Objective-C/UIColor+Chameleon.m
Original file line number Diff line number Diff line change
Expand Up @@ -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: {

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down