Skip to content

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shashankpali committed Jul 22, 2016
1 parent eb9c821 commit 57969b4
Show file tree
Hide file tree
Showing 27 changed files with 1,136 additions and 0 deletions.
Binary file added Assets/Banner.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step1a.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step1b.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step2a.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step2b.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step2c.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step3a.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step3b.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step3c.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step4a.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step4b.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Step4c.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Test.xcf
Binary file not shown.
14 changes: 14 additions & 0 deletions EZYGradientView.podspec
@@ -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
125 changes: 125 additions & 0 deletions EZYGradientView/EZYGradientView.swift
@@ -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)
}
}

0 comments on commit 57969b4

Please sign in to comment.