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
eb9c821
commit 57969b4
Showing
27 changed files
with
1,136 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Pod::Spec.new do |s| | ||
|
||
s.name = 'EZYGradientView' | ||
s.version = '1.0' | ||
s.platform = :ios, '8.0' | ||
s.license = { :type => 'MIT' } | ||
s.homepage = 'https://github.com/shashankpali/EZYGradientView' | ||
s.authors = { 'Shashank Pali' => 'shank.pali@gmail.com' } | ||
s.summary = 'Create gradients without a single line of code' | ||
s.source = { :git => 'https://github.com/shashankpali/EZYGradientView.git', :tag => s.version } | ||
s.source_files = 'EZYGradientView/*.swift' | ||
s.requires_arc = true | ||
|
||
end |
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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// EZYGradientView.swift | ||
// | ||
// Copyright (c) 2016 Shashank Pali | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import UIKit | ||
|
||
@IBDesignable | ||
|
||
public class EZYGradientView: UIView | ||
{ | ||
@IBInspectable public var firstColor: UIColor = UIColor.whiteColor() | ||
@IBInspectable public var secondColor: UIColor = UIColor.whiteColor() | ||
|
||
@IBInspectable public var angleº: Float = 45 | ||
{ | ||
didSet | ||
{ | ||
// handle negative angles | ||
if angleº < 0.0 { | ||
angleº = 360.0 + angleº | ||
} | ||
|
||
// offset of 45 is needed to make logic work | ||
angleº = angleº + 45 | ||
|
||
let multiplier = Int(angleº / 360) | ||
if (multiplier > 0) | ||
{ | ||
angleº = angleº - Float(360 * multiplier) | ||
} | ||
} | ||
} | ||
|
||
@IBInspectable public var colorRatio: Float = 0.5 | ||
@IBInspectable public var fadeIntensity: Float = 0.0 | ||
|
||
private var gradientLayer = CAGradientLayer() | ||
|
||
override public func drawRect(rect: CGRect) | ||
{ | ||
gradientLayer.frame = self.bounds | ||
gradientLayer.colors = [firstColor.CGColor, secondColor.CGColor] | ||
|
||
let points = startEndPoints() | ||
gradientLayer.startPoint = points.0 | ||
gradientLayer.endPoint = points.1 | ||
|
||
let colorLoc = locations() | ||
gradientLayer.locations = [colorLoc.0, colorLoc.1] | ||
|
||
layer.insertSublayer(gradientLayer, atIndex: 0) | ||
} | ||
|
||
private func startEndPoints() -> (CGPoint, CGPoint) | ||
{ | ||
var rotCalX: Float = 0.0 | ||
var rotCalY: Float = 0.0 | ||
|
||
// to convert from 0...360 range to 0...4 | ||
let rotate = angleº / 90 | ||
|
||
// 1...4 can be understood to denote the four quadrants | ||
if rotate <= 1 | ||
{ | ||
rotCalY = rotate | ||
} | ||
else if rotate <= 2 | ||
{ | ||
rotCalY = 1 | ||
rotCalX = rotate - 1 | ||
} | ||
else if rotate <= 3 | ||
{ | ||
rotCalX = 1 | ||
rotCalY = 1 - (rotate - 2) | ||
} | ||
else if rotate <= 4 | ||
{ | ||
rotCalX = 1 - (rotate - 3) | ||
} | ||
|
||
let start = CGPointMake(1 - CGFloat(rotCalY), 0 + CGFloat(rotCalX)) | ||
let end = CGPointMake(0 + CGFloat(rotCalY), 1 - CGFloat(rotCalX)) | ||
|
||
return (start, end) | ||
} | ||
|
||
private func locations() -> (Float, Float) | ||
{ | ||
let divider = fadeIntensity / self.divider() | ||
return(colorRatio - divider, colorRatio + divider) | ||
} | ||
|
||
private func divider() -> Float | ||
{ | ||
if colorRatio == 0.1 | ||
{ | ||
return 10 | ||
} | ||
if colorRatio < 0.5 | ||
{ | ||
let value = 0.5 - colorRatio + 0.5 | ||
return 1 / (1 - value) | ||
} | ||
return 1 / (1 - colorRatio) | ||
} | ||
} |
Oops, something went wrong.