From b3e171e93a482e99f013e9f154ad9cdc19f69c7b Mon Sep 17 00:00:00 2001 From: Amit Tandel Date: Wed, 5 Jul 2017 14:28:22 +0530 Subject: [PATCH 1/6] Rotational Gradient implemented. --- .../xcshareddata/LGButton.xcscmblueprint | 17 +++++-- Example/LGButton/Base.lproj/Main.storyboard | 46 +++++++++++++++++-- LGButton/Classes/LGButton.swift | 28 +++++++++-- 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/Example/LGButton.xcworkspace/xcshareddata/LGButton.xcscmblueprint b/Example/LGButton.xcworkspace/xcshareddata/LGButton.xcscmblueprint index eeed2f7..6f8d61f 100644 --- a/Example/LGButton.xcworkspace/xcshareddata/LGButton.xcscmblueprint +++ b/Example/LGButton.xcworkspace/xcshareddata/LGButton.xcscmblueprint @@ -1,16 +1,18 @@ { - "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "12D60E059AAD3279E7D767CD4C75B4E4F500A231", + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "6783549A778C5AC63ACE412C3FA770AC732A4E21", "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { }, "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { - "12D60E059AAD3279E7D767CD4C75B4E4F500A231" : 9223372036854775807, - "5EDC1C5AD949DF91D2C45B5C3B06C3CDD86B8C1D" : 9223372036854775807 + "5EDC1C5AD949DF91D2C45B5C3B06C3CDD86B8C1D" : 9223372036854775807, + "6783549A778C5AC63ACE412C3FA770AC732A4E21" : 9223372036854775807, + "12D60E059AAD3279E7D767CD4C75B4E4F500A231" : 9223372036854775807 }, "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "355E0413-1FC2-44D6-A4A5-C71A3F3BB5F5", "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { - "12D60E059AAD3279E7D767CD4C75B4E4F500A231" : "LGButton-github\/", - "5EDC1C5AD949DF91D2C45B5C3B06C3CDD86B8C1D" : "LGButton-github\/LGButton\/" + "5EDC1C5AD949DF91D2C45B5C3B06C3CDD86B8C1D" : "LGButton-github\/LGButton\/", + "6783549A778C5AC63ACE412C3FA770AC732A4E21" : "LGButton\/", + "12D60E059AAD3279E7D767CD4C75B4E4F500A231" : "LGButton-github\/" }, "DVTSourceControlWorkspaceBlueprintNameKey" : "LGButton", "DVTSourceControlWorkspaceBlueprintVersion" : 204, @@ -25,6 +27,11 @@ "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "gitlab.com:lorenzo.gr90\/LGButton.git", "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "5EDC1C5AD949DF91D2C45B5C3B06C3CDD86B8C1D" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/am33t\/LGButton", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "6783549A778C5AC63ACE412C3FA770AC732A4E21" } ] } \ No newline at end of file diff --git a/Example/LGButton/Base.lproj/Main.storyboard b/Example/LGButton/Base.lproj/Main.storyboard index 0c7617e..7be176f 100644 --- a/Example/LGButton/Base.lproj/Main.storyboard +++ b/Example/LGButton/Base.lproj/Main.storyboard @@ -1,10 +1,10 @@ - + - + @@ -24,10 +24,10 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LGButton/Classes/LGButton.swift b/LGButton/Classes/LGButton.swift index 45a3d43..4cf44a6 100644 --- a/LGButton/Classes/LGButton.swift +++ b/LGButton/Classes/LGButton.swift @@ -81,6 +81,16 @@ public class LGButton: UIControl { } } + @IBInspectable public var gradientRotation: CGFloat = 0 { + didSet{ + if gradient != nil { + gradient?.removeFromSuperlayer() + gradient = nil + setupView() + } + } + } + @IBInspectable public var cornerRadius: CGFloat = 0.0 { didSet{ setupView() @@ -380,12 +390,20 @@ public class LGButton: UIControl { gradient = CAGradientLayer() gradient!.frame.size = frame.size gradient!.colors = [gradientStartColor!.cgColor, gradientEndColor!.cgColor] - gradient!.startPoint = CGPoint(x: 0, y: 0) - if (gradientHorizontal){ - gradient!.endPoint = CGPoint(x: 1, y: 0) - }else{ - gradient!.endPoint = CGPoint(x: 0, y: 1) + + var xAngle:Float = Float(gradientRotation) + if (gradientHorizontal) + { + xAngle = 0.25 } + + var a:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.75)/2))),2) + var b:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.0)/2))),2) + var c:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.25)/2))),2) + var d:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.5)/2))),2) + gradient!.startPoint = CGPoint(x: CGFloat(a), y: CGFloat(b)) + gradient!.endPoint = CGPoint(x: CGFloat(c), y: CGFloat(d)) + bgContentView.layer.addSublayer(gradient!) } } From f03b08a3737305251c61ed969c21766f753da392 Mon Sep 17 00:00:00 2001 From: Amit Tandel Date: Wed, 5 Jul 2017 22:44:34 +0530 Subject: [PATCH 2/6] Correction 1TBS indent style. --- LGButton/Classes/LGButton.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/LGButton/Classes/LGButton.swift b/LGButton/Classes/LGButton.swift index 4cf44a6..eaea77b 100644 --- a/LGButton/Classes/LGButton.swift +++ b/LGButton/Classes/LGButton.swift @@ -392,11 +392,9 @@ public class LGButton: UIControl { gradient!.colors = [gradientStartColor!.cgColor, gradientEndColor!.cgColor] var xAngle:Float = Float(gradientRotation) - if (gradientHorizontal) - { + if (gradientHorizontal) { xAngle = 0.25 } - var a:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.75)/2))),2) var b:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.0)/2))),2) var c:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.25)/2))),2) From f6043d2a6dbd31828ff13c5a341f178eac35ad4a Mon Sep 17 00:00:00 2001 From: "lorenzo.gr90" Date: Fri, 7 Jul 2017 17:39:51 +0200 Subject: [PATCH 3/6] Code cleaned up, changed interval from 0->1 to -360->360 --- Example/LGButton/Base.lproj/Main.storyboard | 6 +++--- LGButton/Classes/LGButton.swift | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Example/LGButton/Base.lproj/Main.storyboard b/Example/LGButton/Base.lproj/Main.storyboard index 7be176f..c689890 100644 --- a/Example/LGButton/Base.lproj/Main.storyboard +++ b/Example/LGButton/Base.lproj/Main.storyboard @@ -1,10 +1,10 @@ - + - + @@ -735,7 +735,7 @@ - + diff --git a/LGButton/Classes/LGButton.swift b/LGButton/Classes/LGButton.swift index eaea77b..2c854cb 100644 --- a/LGButton/Classes/LGButton.swift +++ b/LGButton/Classes/LGButton.swift @@ -391,14 +391,20 @@ public class LGButton: UIControl { gradient!.frame.size = frame.size gradient!.colors = [gradientStartColor!.cgColor, gradientEndColor!.cgColor] - var xAngle:Float = Float(gradientRotation) + var rotation:CGFloat! + if gradientRotation >= 0 { + rotation = min(gradientRotation, CGFloat(360.0)) + } else { + rotation = max(gradientRotation, CGFloat(-360.0)) + } + var xAngle:Float = Float(rotation/360) if (gradientHorizontal) { xAngle = 0.25 } - var a:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.75)/2))),2) - var b:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.0)/2))),2) - var c:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.25)/2))),2) - var d:Float = pow(sinf((2*Float(M_PI)*((xAngle+0.5)/2))),2) + let a = pow(sinf((2*Float(Double.pi)*((xAngle+0.75)/2))),2) + let b = pow(sinf((2*Float(Double.pi)*((xAngle+0.0)/2))),2) + let c = pow(sinf((2*Float(Double.pi)*((xAngle+0.25)/2))),2) + let d = pow(sinf((2*Float(Double.pi)*((xAngle+0.5)/2))),2) gradient!.startPoint = CGPoint(x: CGFloat(a), y: CGFloat(b)) gradient!.endPoint = CGPoint(x: CGFloat(c), y: CGFloat(d)) From c274bd1dd534a1fff490728bc2f8d15fe9e6831b Mon Sep 17 00:00:00 2001 From: "lorenzo.gr90" Date: Fri, 7 Jul 2017 17:43:32 +0200 Subject: [PATCH 4/6] Readme updated --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 72bdb78..e35418b 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Customise your button by setting the properties from the Interface Builder. | Gradient End Color | The second color of the gradient background | nil | | Gradient End Color | The second color of the gradient background | nil | | Gradient Horizontal | Whether the gradient should be horizontal or not | false | +| Gradient Rotation | Set the gradient rotation angle (degrees from -360 to 360) | 0 | | Corner Radius | The corner radius | 0.0 | | Fully Rounded Corners | Apply a corner radius equals to height/2 | false | | Border Color | The border color | white | From 691a2aaada680e4106d42749524e196abb2d5f14 Mon Sep 17 00:00:00 2001 From: "lorenzo.gr90" Date: Fri, 7 Jul 2017 18:03:12 +0200 Subject: [PATCH 5/6] .gitignore updated --- .gitignore | 5 +++ .../xcshareddata/LGButton.xcscmblueprint | 37 ------------------- 2 files changed, 5 insertions(+), 37 deletions(-) delete mode 100644 Example/LGButton.xcworkspace/xcshareddata/LGButton.xcscmblueprint diff --git a/.gitignore b/.gitignore index c0d01b9..2f26cf2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,8 @@ DerivedData/ *.pbxuser !default.pbxuser xcuserdata/ + +## Other +*.moved-aside +*.xccheckout +*.xcscmblueprint \ No newline at end of file diff --git a/Example/LGButton.xcworkspace/xcshareddata/LGButton.xcscmblueprint b/Example/LGButton.xcworkspace/xcshareddata/LGButton.xcscmblueprint deleted file mode 100644 index 6f8d61f..0000000 --- a/Example/LGButton.xcworkspace/xcshareddata/LGButton.xcscmblueprint +++ /dev/null @@ -1,37 +0,0 @@ -{ - "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "6783549A778C5AC63ACE412C3FA770AC732A4E21", - "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { - - }, - "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { - "5EDC1C5AD949DF91D2C45B5C3B06C3CDD86B8C1D" : 9223372036854775807, - "6783549A778C5AC63ACE412C3FA770AC732A4E21" : 9223372036854775807, - "12D60E059AAD3279E7D767CD4C75B4E4F500A231" : 9223372036854775807 - }, - "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "355E0413-1FC2-44D6-A4A5-C71A3F3BB5F5", - "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { - "5EDC1C5AD949DF91D2C45B5C3B06C3CDD86B8C1D" : "LGButton-github\/LGButton\/", - "6783549A778C5AC63ACE412C3FA770AC732A4E21" : "LGButton\/", - "12D60E059AAD3279E7D767CD4C75B4E4F500A231" : "LGButton-github\/" - }, - "DVTSourceControlWorkspaceBlueprintNameKey" : "LGButton", - "DVTSourceControlWorkspaceBlueprintVersion" : 204, - "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "Example\/LGButton.xcworkspace", - "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ - { - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "github.com:loregr\/LGButton.git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "12D60E059AAD3279E7D767CD4C75B4E4F500A231" - }, - { - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "gitlab.com:lorenzo.gr90\/LGButton.git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "5EDC1C5AD949DF91D2C45B5C3B06C3CDD86B8C1D" - }, - { - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/am33t\/LGButton", - "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", - "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "6783549A778C5AC63ACE412C3FA770AC732A4E21" - } - ] -} \ No newline at end of file From 47fec512458509489409b9bd3100396aa5ae6af9 Mon Sep 17 00:00:00 2001 From: "lorenzo.gr90" Date: Fri, 7 Jul 2017 18:08:07 +0200 Subject: [PATCH 6/6] Prepare for release 1.0.2 --- LGButton.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LGButton.podspec b/LGButton.podspec index def3a17..980dabd 100644 --- a/LGButton.podspec +++ b/LGButton.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'LGButton' - s.version = '1.0.1' + s.version = '1.0.2' s.summary = 'A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code.' s.homepage = 'https://cocoapods.org/pods/LGButton' s.license = { :type => 'MIT', :file => 'LICENSE.md' }