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 eeed2f7..0000000
--- a/Example/LGButton.xcworkspace/xcshareddata/LGButton.xcscmblueprint
+++ /dev/null
@@ -1,30 +0,0 @@
-{
- "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "12D60E059AAD3279E7D767CD4C75B4E4F500A231",
- "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : {
-
- },
- "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : {
- "12D60E059AAD3279E7D767CD4C75B4E4F500A231" : 9223372036854775807,
- "5EDC1C5AD949DF91D2C45B5C3B06C3CDD86B8C1D" : 9223372036854775807
- },
- "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "355E0413-1FC2-44D6-A4A5-C71A3F3BB5F5",
- "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : {
- "12D60E059AAD3279E7D767CD4C75B4E4F500A231" : "LGButton-github\/",
- "5EDC1C5AD949DF91D2C45B5C3B06C3CDD86B8C1D" : "LGButton-github\/LGButton\/"
- },
- "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"
- }
- ]
-}
\ No newline at end of file
diff --git a/Example/LGButton/Base.lproj/Main.storyboard b/Example/LGButton/Base.lproj/Main.storyboard
index 0c7617e..c689890 100644
--- a/Example/LGButton/Base.lproj/Main.storyboard
+++ b/Example/LGButton/Base.lproj/Main.storyboard
@@ -24,10 +24,10 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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' }
diff --git a/LGButton/Classes/LGButton.swift b/LGButton/Classes/LGButton.swift
index 45a3d43..2c854cb 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,24 @@ 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 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
}
+ 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))
+
bgContentView.layer.addSublayer(gradient!)
}
}
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 |