Skip to content

Commit

Permalink
Merge pull request #4 from lm2343635/master
Browse files Browse the repository at this point in the history
Xcode 10.2 and Swift 5.
  • Loading branch information
dqhieu authored Apr 10, 2019
2 parents ca90114 + da2b4db commit 4efe3c7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 38 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0
48 changes: 24 additions & 24 deletions Sources/GradientLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,99 +53,99 @@ open class GradientLayer: CAGradientLayer {
}

public extension GradientLayer {
public static var oceanBlue: GradientLayer {
static var oceanBlue: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight, colors: [UIColor.hex("2E3192"), UIColor.hex("1BFFFF")])
}

public static var sanguine: GradientLayer {
static var sanguine: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("D4145A"), UIColor.hex("FBB03B")])
}

public static var lusciousLime: GradientLayer {
static var lusciousLime: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("009245"), UIColor.hex("FCEE21")])
}

public static var purpleLake: GradientLayer {
static var purpleLake: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("662D8C"), UIColor.hex("ED1E79")])
}

public static var freshPapaya: GradientLayer {
static var freshPapaya: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("ED1C24"), UIColor.hex("FCEE21")])
}

public static var ultramarine: GradientLayer {
static var ultramarine: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("00A8C5"), UIColor.hex("FFFF7E")])
}

public static var pinkSugar: GradientLayer {
static var pinkSugar: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("D74177"), UIColor.hex("FFE98A")])
}

public static var lemonDrizzle: GradientLayer {
static var lemonDrizzle: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("FB872B"), UIColor.hex("D9E021")])
}

public static var victoriaPurple: GradientLayer {
static var victoriaPurple: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("312A6C"), UIColor.hex("852D91")])
}

public static var springGreens: GradientLayer {
static var springGreens: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("009E00"), UIColor.hex("FFFF96")])
}

public static var mysticMauve: GradientLayer {
static var mysticMauve: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("B066FE"), UIColor.hex("63E2FF")])
}

public static var reflexSilver: GradientLayer {
static var reflexSilver: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("808080"), UIColor.hex("E6E6E6")])
}

public static var neonGlow: GradientLayer {
static var neonGlow: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("00FFA1"), UIColor.hex("00FFFF")])
}

public static var berrySmoothie: GradientLayer {
static var berrySmoothie: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("8E78FF"), UIColor.hex("FC7D7B")])
}

public static var newLeaf: GradientLayer {
static var newLeaf: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("00537E"), UIColor.hex("3AA17E")])
}

public static var cottonCandy: GradientLayer {
static var cottonCandy: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("FCA5F1"), UIColor.hex("B5FFFF")])
}

public static var pixieDust: GradientLayer {
static var pixieDust: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("D585FF"), UIColor.hex("00FFEE")])
}

public static var fizzyPeach: GradientLayer {
static var fizzyPeach: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("F24645"), UIColor.hex("EBC08D")])
}

public static var sweetDream: GradientLayer {
static var sweetDream: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("3A3897"), UIColor.hex("A3A1FF")])
}

public static var firebrick: GradientLayer {
static var firebrick: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("45145A"), UIColor.hex("FF5300")])
}

public static var wroughtIron: GradientLayer {
static var wroughtIron: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("333333"), UIColor.hex("5A5454")])
}

public static var deepSea: GradientLayer {
static var deepSea: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("4F00BC"), UIColor.hex("29ABE2")])
}

public static var coastalBreeze: GradientLayer {
static var coastalBreeze: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("00B7FF"), UIColor.hex("FFFFC7")])
}

public static var eveningDelight: GradientLayer {
static var eveningDelight: GradientLayer {
return GradientLayer(direction: .bottomLeftToTopRight , colors: [UIColor.hex("93278F"), UIColor.hex("00A99D")])
}
}
16 changes: 8 additions & 8 deletions Sources/UIGradientExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import UIKit

public extension UIView {

public func addGradientWithDirection(_ direction: GradientDirection, colors: [UIColor], cornerRadius: CGFloat = 0, locations: [Double]? = nil) {
func addGradientWithDirection(_ direction: GradientDirection, colors: [UIColor], cornerRadius: CGFloat = 0, locations: [Double]? = nil) {
let gradientLayer = GradientLayer(direction: direction, colors: colors, cornerRadius: cornerRadius, locations: locations)
self.addGradient(gradientLayer)
}

public func addGradient(_ gradientLayer: GradientLayer, cornerRadius: CGFloat = 0) {
func addGradient(_ gradientLayer: GradientLayer, cornerRadius: CGFloat = 0) {
let cloneGradient = gradientLayer.clone()
cloneGradient.frame = self.bounds
cloneGradient.cornerRadius = cornerRadius
Expand All @@ -25,28 +25,28 @@ public extension UIView {

public extension UIColor {

public static func hex(_ hex: String, alpha: CGFloat = 1.0) -> UIColor {
static func hex(_ hex: String, alpha: CGFloat = 1.0) -> UIColor {
guard let hex = Int(hex, radix: 16) else { return UIColor.clear }
return UIColor(red: ((CGFloat)((hex & 0xFF0000) >> 16)) / 255.0,
green: ((CGFloat)((hex & 0x00FF00) >> 8)) / 255.0,
blue: ((CGFloat)((hex & 0x0000FF) >> 0)) / 255.0,
alpha: alpha)
}

public static func fromGradient(_ gradient: GradientLayer, frame: CGRect, cornerRadius: CGFloat = 0) -> UIColor? {
static func fromGradient(_ gradient: GradientLayer, frame: CGRect, cornerRadius: CGFloat = 0) -> UIColor? {
guard let image = UIImage.fromGradient(gradient, frame: frame, cornerRadius: cornerRadius) else { return nil }
return UIColor(patternImage: image)
}

public static func fromGradientWithDirection(_ direction: GradientDirection, frame: CGRect, colors: [UIColor], cornerRadius: CGFloat = 0, locations: [Double]? = nil) -> UIColor? {
static func fromGradientWithDirection(_ direction: GradientDirection, frame: CGRect, colors: [UIColor], cornerRadius: CGFloat = 0, locations: [Double]? = nil) -> UIColor? {
let gradient = GradientLayer(direction: direction, colors: colors, cornerRadius: cornerRadius, locations: locations)
return UIColor.fromGradient(gradient, frame: frame)
}
}

public extension UIImage {

public static func fromGradient(_ gradient: GradientLayer, frame: CGRect, cornerRadius: CGFloat = 0) -> UIImage? {
static func fromGradient(_ gradient: GradientLayer, frame: CGRect, cornerRadius: CGFloat = 0) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(frame.size, false, UIScreen.main.scale)
guard let ctx = UIGraphicsGetCurrentContext() else { return nil }
let cloneGradient = gradient.clone()
Expand All @@ -58,9 +58,9 @@ public extension UIImage {
return image
}

public static func fromGradientWithDirection(_ direction: GradientDirection, frame: CGRect, colors: [UIColor], cornerRadius: CGFloat = 0, locations: [Double]? = nil) -> UIImage? {
static func fromGradientWithDirection(_ direction: GradientDirection, frame: CGRect, colors: [UIColor], cornerRadius: CGFloat = 0, locations: [Double]? = nil) -> UIImage? {
let gradient = GradientLayer(direction: direction, colors: colors, cornerRadius: cornerRadius, locations: locations)
return UIImage.fromGradient(gradient, frame: frame)
}
}

}
4 changes: 2 additions & 2 deletions UIGradient.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "UIGradient"
s.version = "1.2.0"
s.version = "1.3"
s.summary = "A simple and powerful library for using gradient image, color"
s.homepage = "https://github.com/dqhieu/UIGradient"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand All @@ -10,4 +10,4 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/dqhieu/UIGradient.git", :tag => "#{s.version}" }
s.source_files = "Sources/*.swift"

end
end
8 changes: 4 additions & 4 deletions UIGradientExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand Down Expand Up @@ -299,7 +299,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -315,7 +315,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.dqhieu.UIGradientExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -331,7 +331,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.dqhieu.UIGradientExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down

0 comments on commit 4efe3c7

Please sign in to comment.