-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e2ab69
commit 92bd4a5
Showing
1 changed file
with
26 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
## Smooth gradients on iOS using CGShading | ||
# Smooth gradients on iOS using CGShading | ||
|
||
First, compare the two images below: | ||
This project includes the class `JSTGradientView` which is a `UIView` subclass that can be used wherever a smooth gradient is needed. | ||
This is a replacement for manually drawing a gradient using `CGGradient`. The class used `CGShading` internally instead. | ||
To see why, look at the two images below: | ||
|
||
  | ||
|
||
The first one is drawn using the class published here (JSTGradientView) with a slope factor of 2, the second one is drawn using a linear CGGradient. Guess which one designers usually draw in Photoshop? Yep, the first one. | ||
The first one is drawn using `JSTGradientView` with an interpolation factor of 2, the second one is drawn using `CGGradient`. | ||
Guess which one designers usually put in their designs? Yep, the first one. Most image editing software does a better job at interpolating colors than `CGGradient` | ||
and to mimic that `JSTGradientView` was born. | ||
|
||
Check out the code and comments for more. | ||
Check out the code and sample app to see how the interpolation factor affects the gradient. | ||
|
||
A full **Swift 2** version of the class is available in the branch [swift2](https://github.com/jernejstrasner/Smooth-Gradient/tree/swift2). | ||
|
||
## Setup | ||
|
||
### Carthage | ||
|
||
Start by adding the following line to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile). | ||
```ruby | ||
github "jernejstrasner/Smooth-Gradient" ~> 1.0 | ||
``` | ||
The run | ||
```sh | ||
carthage update | ||
``` | ||
and add the built frameworks to your Xcode project. | ||
|
||
Full instructions on installing dependencies with Carthage can be found in [Carthage's README](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application). |