Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
loregr committed Jul 7, 2017
2 parents d6f3213 + 47fec51 commit ab9e2cb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ DerivedData/
*.pbxuser
!default.pbxuser
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
30 changes: 0 additions & 30 deletions Example/LGButton.xcworkspace/xcshareddata/LGButton.xcscmblueprint

This file was deleted.

42 changes: 40 additions & 2 deletions Example/LGButton/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<rect key="frame" x="0.0" y="20" width="375" height="1980"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Btu-bB-OF4">
<rect key="frame" x="0.0" y="0.0" width="375" height="1357"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="1466.5"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" alignment="center" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="vMc-PO-YZ4">
<rect key="frame" x="16" y="16" width="343" height="1325"/>
<rect key="frame" x="16" y="16" width="343" height="1434.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Flat background" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h5A-IU-0Ih">
<rect key="frame" x="109.5" y="0.0" width="124" height="20.5"/>
Expand Down Expand Up @@ -713,6 +713,44 @@
<action selector="action:" destination="BYZ-38-t0r" eventType="touchUpInside" id="QW9-A0-Qkm"/>
</connections>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Gradient with Rotation" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2sJ-rd-SU2">
<rect key="frame" x="86.5" y="1341" width="170.5" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="S4I-pc-OhJ" customClass="LGButton" customModule="LGButton">
<rect key="frame" x="126" y="1377.5" width="91" height="57"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="bgColor">
<color key="value" red="0.0" green="0.51764705879999995" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="string" keyPath="titleString" value="TRY ME"/>
<userDefinedRuntimeAttribute type="boolean" keyPath="showTouchFeedback" value="YES"/>
<userDefinedRuntimeAttribute type="color" keyPath="gradientStartColor">
<color key="value" red="0.90196078430000004" green="0.2901960784" blue="0.23529411759999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="gradientEndColor">
<color key="value" red="0.1176470588" green="0.26274509800000001" blue="0.41176470590000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="gradientRotation">
<real key="value" value="45"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="spacingTop">
<real key="value" value="20"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="spacingBottom">
<real key="value" value="20"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="spacingLeading">
<real key="value" value="20"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="spacingTrailing">
<real key="value" value="20"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
</stackView>
</subviews>
Expand Down
2 changes: 1 addition & 1 deletion LGButton.podspec
Original file line number Diff line number Diff line change
@@ -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' }
Expand Down
32 changes: 27 additions & 5 deletions LGButton/Classes/LGButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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!)
}
}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down

0 comments on commit ab9e2cb

Please sign in to comment.