Skip to content
Open
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
50 changes: 25 additions & 25 deletions EZYGradientView/EZYGradientView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import UIKit

@IBDesignable

open class EZYGradientView: UIView
public class EZYGradientView: UIView
{

//MARK:- Properties
/// First color of gradient i.e. it appears on top when angleº set to 0.0.
@IBInspectable open var firstColor: UIColor = UIColor.white
@IBInspectable public var firstColor: UIColor = .white
{
didSet
{
Expand All @@ -41,7 +41,7 @@ open class EZYGradientView: UIView
}

/// Second color of gradient i.e. it appears in bottom when angleº set to 0.0.
@IBInspectable open var secondColor: UIColor = UIColor.white
@IBInspectable public var secondColor: UIColor = .white
{
didSet
{
Expand All @@ -53,7 +53,7 @@ open class EZYGradientView: UIView
}

/// Angleº will describe the tilt of gradient.
@IBInspectable open var angleº: Float = 45.0
@IBInspectable public var angleº: Float = 45.0
{
didSet
{
Expand All @@ -79,7 +79,7 @@ open class EZYGradientView: UIView
}

/// Color ratio will describe the proportion of colors. It's value ranges from 0.0 to 1.0 default is 0.5.
@IBInspectable open var colorRatio: Float = 0.5
@IBInspectable public var colorRatio: Float = 0.5
{
didSet
{
Expand All @@ -92,7 +92,7 @@ open class EZYGradientView: UIView
}

/// Fade intensity will describe the disperse of colors. It's value ranges from 0.0 to 1.0 default is 0.0.
@IBInspectable open var fadeIntensity: Float = 0.0
@IBInspectable public var fadeIntensity: Float = 0.0
{
didSet
{
Expand All @@ -105,7 +105,7 @@ open class EZYGradientView: UIView
}

/// Is blur allow to add visual effect on gradient view. Can't be change during run-time.
@IBInspectable open var isBlur: Bool = false
@IBInspectable public var isBlur: Bool = false
{
didSet
{
Expand All @@ -116,7 +116,7 @@ open class EZYGradientView: UIView
}
}
/// Blur opacity will describe the transparency of blur. It's value ranges from 0.0 to 1.0 default is 0.0. It is suggested to set EZYGradientView background color as clear color for better results.
@IBInspectable open var blurOpacity: Float = 0.0
@IBInspectable public var blurOpacity: Float = 0.0
{
didSet
{
Expand All @@ -128,33 +128,33 @@ open class EZYGradientView: UIView
}
}

fileprivate var blurView: UIVisualEffectView?
open var blurLayer: CALayer?
open var gradientLayer: CAGradientLayer?
private var blurView: UIVisualEffectView?
public var blurLayer: CALayer?
public var gradientLayer: CAGradientLayer?

//MARK:- Designated Initializer

override init(frame: CGRect)
{
super.init(frame: frame)
self.backgroundColor = UIColor.clear
self.backgroundColor = .clear
}

public required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
self.backgroundColor = UIColor.clear
self.backgroundColor = .clear
}

//MARK:- Draw Rect with steps

override open func draw(_ rect: CGRect)
override public func draw(_ rect: CGRect)
{
if gradientLayer == nil
{
gradientLayer = CAGradientLayer()
gradientLayer!.frame = self.bounds
layer.insertSublayer(gradientLayer!, at: 0)
layer.insertSublayer(gradientLayer!, at: 0)
}
self.updateColors()
self.updatePoints()
Expand All @@ -164,14 +164,14 @@ open class EZYGradientView: UIView
/**
Step 1
*/
fileprivate func updateColors()
private func updateColors()
{
gradientLayer!.colors = [firstColor.cgColor, secondColor.cgColor]
}
/**
Step 2
*/
fileprivate func updatePoints()
private func updatePoints()
{
let points = startEndPoints()
gradientLayer!.startPoint = points.0
Expand All @@ -180,15 +180,15 @@ open class EZYGradientView: UIView
/**
Step 3
*/
fileprivate func updateLocation()
private func updateLocation()
{
let colorLoc = locations()
gradientLayer!.locations = [NSNumber(value: colorLoc.0), NSNumber(value: colorLoc.1)]
gradientLayer!.locations = [NSNumber(value: colorLoc.0), NSNumber(value: colorLoc.1)]
}
/**
Step 4
*/
fileprivate func checkBlurStatusAndUpdateOpacity()
private func checkBlurStatusAndUpdateOpacity()
{
if isBlur
{
Expand All @@ -199,7 +199,7 @@ open class EZYGradientView: UIView
blurView?.frame = self.bounds
blurLayer = blurView?.layer
}
gradientLayer!.colors = [blurColor(firstColor), blurColor(secondColor)]
gradientLayer!.colors = [blurColor(color: firstColor), blurColor(color: secondColor)]
self.layer.insertSublayer(blurLayer!, below: gradientLayer)
}
else
Expand All @@ -212,12 +212,12 @@ open class EZYGradientView: UIView

//MARK:- Helpers

fileprivate func blurColor(_ color: UIColor) -> CGColor
private func blurColor(color: UIColor) -> CGColor
{
return color.withAlphaComponent(CGFloat(0.9 - (blurOpacity / 2))).cgColor
}

fileprivate func startEndPoints() -> (CGPoint, CGPoint)
private func startEndPoints() -> (CGPoint, CGPoint)
{
var rotCalX: Float = 0.0
var rotCalY: Float = 0.0
Expand Down Expand Up @@ -251,13 +251,13 @@ open class EZYGradientView: UIView
return (start, end)
}

fileprivate func locations() -> (Float, Float)
private func locations() -> (Float, Float)
{
let divider = fadeIntensity / self.divider()
return(colorRatio - divider, colorRatio + divider)
}

fileprivate func divider() -> Float
private func divider() -> Float
{
if colorRatio == 0.1
{
Expand Down