Skip to content

Commit

Permalink
Adde gradient to inspectable view. Updated version number.
Browse files Browse the repository at this point in the history
  • Loading branch information
melvitax committed Jul 22, 2016
1 parent d076e4b commit 7563677
Show file tree
Hide file tree
Showing 9 changed files with 385 additions and 326 deletions.
2 changes: 1 addition & 1 deletion AFViewHelper.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AFViewHelper'
s.version = '4.0.1'
s.version = '4.1.0'
s.platform = :ios, '8.0'
s.license = 'MIT'
s.summary = 'Autolayout and Animation UIVIew Extension for Swift 2.0.'
Expand Down
5 changes: 3 additions & 2 deletions AFViewHelper/AFInspectableButton.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//
// AFInspectableButton.swift
// News Proto
//
// AFViewExtension: Version 4.1.0
//
// Created by Melvin Rivera on 6/28/16.
// Copyright © 2016 NBC News. All rights reserved.
// https://github.com/melvitax/AFViewHelper
//

import Foundation
Expand Down
80 changes: 69 additions & 11 deletions AFViewHelper/AFInspectableView.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
//
// AF+Inspectable+View.swift
//
// AFViewExtension: Version 4.0.1
// AFViewExtension: Version 4.1.0
//
// Created by Melvin Rivera on 7/24/14.
// Copyright (c) 2014 All Forces. All rights reserved.
// https://github.com/melvitax/AFViewHelper
//


import Foundation
import UIKit
import QuartzCore

@IBDesignable public class AFInspectableView :UIView {


// MARK: Border

/**
The layer border color
*/
The layer border color
*/
@IBInspectable override var borderColor: UIColor {
get {
return layer.borderColor == nil ? UIColor.clearColor() : UIColor(CGColor: layer.borderColor!)
Expand All @@ -45,24 +45,25 @@ import QuartzCore
// MARK: Corner Radius

/**
The layer corner radius
*/
The layer corner radius
*/
@IBInspectable override var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
setupView()
}
}


// MARK: Shadow

/**
The shadow color of the layer
*/
The shadow color of the layer
*/
@IBInspectable override var shadowColor: UIColor {
get {
return layer.shadowColor == nil ? UIColor.clearColor() : UIColor(CGColor: layer.shadowColor!)
Expand Down Expand Up @@ -112,6 +113,63 @@ import QuartzCore
layer.shadowRadius = newValue
}
}



// MARK: Inspectable properties

@IBInspectable var startColor: UIColor = UIColor.whiteColor() {
didSet{
setupView()
}
}

@IBInspectable var endColor: UIColor = UIColor.blackColor() {
didSet{
setupView()
}
}

@IBInspectable var isHorizontal: Bool = false {
didSet{
setupView()
}
}


// MARK: Internal functions

private func setupView(){
let colors = [startColor.CGColor, endColor.CGColor]
gradientLayer.colors = colors
gradientLayer.cornerRadius = cornerRadius
if (isHorizontal){
gradientLayer.endPoint = CGPoint(x: 1, y: 0)
} else {
gradientLayer.endPoint = CGPoint(x: 0, y: 1)
}
self.setNeedsDisplay()
}

// Helper to return the main layer as CAGradientLayer
var gradientLayer: CAGradientLayer {
return layer as! CAGradientLayer
}


// MARK: Overrides ******************************************

override public class func layerClass()->AnyClass{
return CAGradientLayer.self
}

override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}

required public init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
setupView()
}


}
Loading

0 comments on commit 7563677

Please sign in to comment.