Skip to content

Commit

Permalink
Merge branch 'release/1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
loregr committed Dec 22, 2018
2 parents 01d76dc + 9193606 commit 6500647
Show file tree
Hide file tree
Showing 29 changed files with 3,833 additions and 3,554 deletions.
2 changes: 1 addition & 1 deletion .swift-version
@@ -1 +1 @@
4.0
4.2
6 changes: 3 additions & 3 deletions .travis.yml
@@ -1,14 +1,14 @@
osx_image: xcode9
osx_image: xcode10
language: objective-c

before_script:
- cd Example
- pod install

script:
- xcodebuild clean build -sdk iphonesimulator11.0 -workspace LGButton.xcworkspace -scheme LGButton-Example CODE_SIGNING_REQUIRED=NO
- xcodebuild clean build -sdk iphonesimulator12.0 -workspace LGButton.xcworkspace -scheme LGButton-Example CODE_SIGNING_REQUIRED=NO

branches:
only:
- master
- develop
- develop
4 changes: 2 additions & 2 deletions Example/LGButton.xcodeproj/project.pbxproj
Expand Up @@ -379,7 +379,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -396,7 +396,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Example/LGButton/AppDelegate.swift
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
175 changes: 146 additions & 29 deletions Example/LGButton/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Example/LGButton/ViewController.swift
Expand Up @@ -20,7 +20,5 @@ class ViewController: UIViewController {
// DO SOMETHING
}
}


}

76 changes: 38 additions & 38 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion LGButton.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'LGButton'
s.version = '1.0.5'
s.version = '1.1'
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
148 changes: 104 additions & 44 deletions LGButton/Classes/LGButton.swift
Expand Up @@ -16,11 +16,17 @@ public class LGButton: UIControl {
case touched = 0.7
case untouched = 1.0
}

let touchDisableRadius : CGFloat = 100.0

let availableFontIcons = ["fa", "io", "oc", "ic", "ma", "ti", "mi"]

private var availableFontIcons: [String: IconFont] = ["fa": Fonts.awesome,
"io": Fonts.ion,
"oc": Fonts.oct,
"ic": Fonts.ic,
"ma": Fonts.material,
"ti": Fonts.themify,
"mi": Fonts.map]

var gradient : CAGradientLayer?


Expand Down Expand Up @@ -53,7 +59,7 @@ public class LGButton: UIControl {

public var isLoading = false {
didSet {
showLoadingView()
showLoadingView()
}
}

Expand Down Expand Up @@ -148,6 +154,12 @@ public class LGButton: UIControl {
}
}

@IBInspectable public var titleNumOfLines: Int = 1 {
didSet{
setupView()
}
}

@IBInspectable public var verticalOrientation: Bool = false {
didSet {
setupView()
Expand Down Expand Up @@ -334,16 +346,38 @@ public class LGButton: UIControl {
}
}

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

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

// MARK: - Standard Properties
// MARK:
public var attributedString: NSAttributedString? {
didSet {
titleLbl.attributedText = attributedString
}
}

// MARK: - Overrides
// MARK:
override init(frame: CGRect) {
super.init(frame: frame)
registIconFont()
xibSetup()
setupView()
}

required public init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
registIconFont()
xibSetup()
setupView()
}
Expand All @@ -357,6 +391,18 @@ public class LGButton: UIControl {
setupBorderAndCorners()
}

override public func awakeFromNib() {
super.awakeFromNib()
xibSetup()
setupView()
}

override public func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
xibSetup()
setupView()
}

override public var intrinsicContentSize: CGSize {
return CGSize(width: 10, height: 10)
}
Expand All @@ -369,17 +415,24 @@ public class LGButton: UIControl {
bgContentView.clipsToBounds = true
layer.masksToBounds = false
setIconOrientation()
setupTitle()
setupBackgroundColor()
setupGradientBackground()
setupBorderAndCorners()
setupTitle()
setupLeftIcon()
setupRightIcon()
setupLeftImage()
setupRightImage()
setupSpacings()
setupShadow()
setupLoadingView()
setupAlignment()
}

fileprivate func registIconFont() {
for (key, value) in self.availableFontIcons {
SwiftIconFont.registFont(from: value, name: key)
}
}

fileprivate func setIconOrientation() {
Expand Down Expand Up @@ -416,7 +469,7 @@ public class LGButton: UIControl {
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 All @@ -435,6 +488,7 @@ public class LGButton: UIControl {

fileprivate func setupTitle() {
titleLbl.isHidden = titleString.isEmpty
titleLbl.numberOfLines = titleNumOfLines
titleLbl.text = titleString
titleLbl.textColor = titleColor
if titleFontName != nil {
Expand Down Expand Up @@ -468,7 +522,7 @@ public class LGButton: UIControl {
heightConstraint: leftImageHeightConstraint,
widthValue: leftImageWidth,
heightValue: leftImageHeight)
leftIcon.isHidden = (leftImageSrc != nil || !availableFontIcons.contains(leftIconFontName))
leftIcon.isHidden = (leftImageSrc != nil || !(SwiftIconFont.fonts[leftIconFontName] != nil))
}

fileprivate func setupRightImage(){
Expand All @@ -480,7 +534,7 @@ public class LGButton: UIControl {
heightConstraint: rightImageHeightConstraint,
widthValue: rightImageWidth,
heightValue: rightImageHeight)
rightIcon.isHidden = (rightImageSrc != nil || !availableFontIcons.contains(rightIconFontName))
rightIcon.isHidden = (rightImageSrc != nil || !(SwiftIconFont.fonts[rightIconFontName] != nil))
}

fileprivate func setupSpacings(){
Expand Down Expand Up @@ -512,44 +566,42 @@ public class LGButton: UIControl {
setupBorderAndCorners()
}

fileprivate func setupAlignment() {
if leftAligned {
titleLbl.textAlignment = .left
} else if rightAligned {
titleLbl.textAlignment = .right
} else {
titleLbl.textAlignment = .center
}
}

fileprivate func setupIcon(icon:UILabel, fontName:String, iconName:String, fontSize:CGFloat, color:UIColor){
icon.isHidden = !availableFontIcons.contains(fontName)
if !icon.isHidden {
defer {
setupBorderAndCorners()
}
if let iconFont = SwiftIconFont.fonts[fontName] {
icon.isHidden = false
icon.textColor = color
switch fontName {
case "fa":
icon.font = UIFont.icon(from: .FontAwesome, ofSize: fontSize)
icon.text = String.fontAwesomeIcon(iconName)
break;
case "io":
icon.font = UIFont.icon(from: .Ionicon, ofSize: fontSize)
icon.text = String.fontIonIcon(iconName)
break;
case "oc":
icon.font = UIFont.icon(from: .Octicon, ofSize: fontSize)
icon.text = String.fontOcticon(iconName)
break;
case "ic":
icon.font = UIFont.icon(from: .Iconic, ofSize: fontSize)
icon.text = String.fontIconicIcon(iconName)
break;
case "ma":
icon.font = UIFont.icon(from: .MaterialIcon, ofSize: fontSize)
icon.text = String.fontMaterialIcon(iconName.replacingOccurrences(of: "-", with: "."))
break;
case "ti":
icon.font = UIFont.icon(from: .Themify, ofSize: fontSize)
icon.text = String.fontThemifyIcon(iconName.replacingOccurrences(of: "-", with: "."))
break;
case "mi":
icon.font = UIFont.icon(from: .MapIcon, ofSize: fontSize)
icon.text = String.fontMapIcon(iconName.replacingOccurrences(of: "-", with: "."))
break;
default:
break;
icon.font = UIFont.icon(from: iconFont, ofSize: fontSize)
if let iconStr = String.getIcon(from: iconFont, code: iconName) {
icon.text = iconStr
}else{
let joind = ["-", ".", "_"]
for left in joind {
for right in joind {
if left == right { continue }
let code = iconName.replacingOccurrences(of: left, with: right)
if let iconStr = String.getIcon(from: iconFont, code: code) {
icon.text = iconStr
return
}
}
}
}
}else{
icon.isHidden = true
}
setupBorderAndCorners()
}

fileprivate func setupImage(imageView:UIImageView, image:UIImage?, color:UIColor?, widthConstraint:NSLayoutConstraint, heightConstraint:NSLayoutConstraint, widthValue:CGFloat, heightValue:CGFloat){
Expand Down Expand Up @@ -581,7 +633,7 @@ public class LGButton: UIControl {
fileprivate func xibSetup() {
rootView = loadViewFromNib()
rootView.frame = bounds
rootView.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
rootView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
addSubview(rootView)
leadingLoadingConstraint.isActive = false
trailingLoadingConstraint.isActive = false
Expand Down Expand Up @@ -613,7 +665,7 @@ public class LGButton: UIControl {
touchAlpha = (pressed) ? .touched : .untouched
}
}

override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
pressed = true
}
Expand Down Expand Up @@ -651,4 +703,12 @@ public class LGButton: UIControl {
}
}
}

@IBAction func tapAction(_ sender: Any) {
let shouldSendActions = pressed
pressed = false
if shouldSendActions{
sendActions(for: .touchUpInside)
}
}
}

0 comments on commit 6500647

Please sign in to comment.