Skip to content

Commit 6500647

Browse files
committed
Merge branch 'release/1.1'
2 parents 01d76dc + 9193606 commit 6500647

29 files changed

Lines changed: 3833 additions & 3554 deletions

.swift-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0
1+
4.2

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
osx_image: xcode9
1+
osx_image: xcode10
22
language: objective-c
33

44
before_script:
55
- cd Example
66
- pod install
77

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

1111
branches:
1212
only:
1313
- master
14-
- develop
14+
- develop

Example/LGButton.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@
379379
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
380380
PRODUCT_NAME = "$(TARGET_NAME)";
381381
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
382-
SWIFT_VERSION = 4.0;
382+
SWIFT_VERSION = 4.2;
383383
};
384384
name = Debug;
385385
};
@@ -396,7 +396,7 @@
396396
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
397397
PRODUCT_NAME = "$(TARGET_NAME)";
398398
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
399-
SWIFT_VERSION = 4.0;
399+
SWIFT_VERSION = 4.2;
400400
};
401401
name = Release;
402402
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Example/LGButton/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
17+
private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}

Example/LGButton/Base.lproj/Main.storyboard

Lines changed: 146 additions & 29 deletions
Large diffs are not rendered by default.

Example/LGButton/ViewController.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,5 @@ class ViewController: UIViewController {
2020
// DO SOMETHING
2121
}
2222
}
23-
24-
2523
}
2624

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LGButton.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'LGButton'
3-
s.version = '1.0.5'
3+
s.version = '1.1'
44
s.summary = 'A fully customisable subclass of the native UIControl which allows you to create beautiful buttons without writing any line of code.'
55
s.homepage = 'https://cocoapods.org/pods/LGButton'
66
s.license = { :type => 'MIT', :file => 'LICENSE.md' }

LGButton/Classes/LGButton.swift

Lines changed: 104 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ public class LGButton: UIControl {
1616
case touched = 0.7
1717
case untouched = 1.0
1818
}
19-
19+
2020
let touchDisableRadius : CGFloat = 100.0
2121

22-
let availableFontIcons = ["fa", "io", "oc", "ic", "ma", "ti", "mi"]
23-
22+
private var availableFontIcons: [String: IconFont] = ["fa": Fonts.awesome,
23+
"io": Fonts.ion,
24+
"oc": Fonts.oct,
25+
"ic": Fonts.ic,
26+
"ma": Fonts.material,
27+
"ti": Fonts.themify,
28+
"mi": Fonts.map]
29+
2430
var gradient : CAGradientLayer?
2531

2632

@@ -53,7 +59,7 @@ public class LGButton: UIControl {
5359

5460
public var isLoading = false {
5561
didSet {
56-
showLoadingView()
62+
showLoadingView()
5763
}
5864
}
5965

@@ -148,6 +154,12 @@ public class LGButton: UIControl {
148154
}
149155
}
150156

157+
@IBInspectable public var titleNumOfLines: Int = 1 {
158+
didSet{
159+
setupView()
160+
}
161+
}
162+
151163
@IBInspectable public var verticalOrientation: Bool = false {
152164
didSet {
153165
setupView()
@@ -334,16 +346,38 @@ public class LGButton: UIControl {
334346
}
335347
}
336348

349+
@IBInspectable public var leftAligned: Bool = false {
350+
didSet{
351+
setupView()
352+
}
353+
}
354+
355+
@IBInspectable public var rightAligned: Bool = false {
356+
didSet{
357+
setupView()
358+
}
359+
}
360+
361+
// MARK: - Standard Properties
362+
// MARK:
363+
public var attributedString: NSAttributedString? {
364+
didSet {
365+
titleLbl.attributedText = attributedString
366+
}
367+
}
368+
337369
// MARK: - Overrides
338370
// MARK:
339371
override init(frame: CGRect) {
340372
super.init(frame: frame)
373+
registIconFont()
341374
xibSetup()
342375
setupView()
343376
}
344377

345378
required public init(coder aDecoder: NSCoder) {
346379
super.init(coder: aDecoder)!
380+
registIconFont()
347381
xibSetup()
348382
setupView()
349383
}
@@ -357,6 +391,18 @@ public class LGButton: UIControl {
357391
setupBorderAndCorners()
358392
}
359393

394+
override public func awakeFromNib() {
395+
super.awakeFromNib()
396+
xibSetup()
397+
setupView()
398+
}
399+
400+
override public func prepareForInterfaceBuilder() {
401+
super.prepareForInterfaceBuilder()
402+
xibSetup()
403+
setupView()
404+
}
405+
360406
override public var intrinsicContentSize: CGSize {
361407
return CGSize(width: 10, height: 10)
362408
}
@@ -369,17 +415,24 @@ public class LGButton: UIControl {
369415
bgContentView.clipsToBounds = true
370416
layer.masksToBounds = false
371417
setIconOrientation()
418+
setupTitle()
372419
setupBackgroundColor()
373420
setupGradientBackground()
374421
setupBorderAndCorners()
375-
setupTitle()
376422
setupLeftIcon()
377423
setupRightIcon()
378424
setupLeftImage()
379425
setupRightImage()
380426
setupSpacings()
381427
setupShadow()
382428
setupLoadingView()
429+
setupAlignment()
430+
}
431+
432+
fileprivate func registIconFont() {
433+
for (key, value) in self.availableFontIcons {
434+
SwiftIconFont.registFont(from: value, name: key)
435+
}
383436
}
384437

385438
fileprivate func setIconOrientation() {
@@ -416,7 +469,7 @@ public class LGButton: UIControl {
416469
let d = pow(sinf((2*Float(Double.pi)*((xAngle+0.5)/2))),2)
417470
gradient!.startPoint = CGPoint(x: CGFloat(a), y: CGFloat(b))
418471
gradient!.endPoint = CGPoint(x: CGFloat(c), y: CGFloat(d))
419-
472+
420473
bgContentView.layer.addSublayer(gradient!)
421474
}
422475
}
@@ -435,6 +488,7 @@ public class LGButton: UIControl {
435488

436489
fileprivate func setupTitle() {
437490
titleLbl.isHidden = titleString.isEmpty
491+
titleLbl.numberOfLines = titleNumOfLines
438492
titleLbl.text = titleString
439493
titleLbl.textColor = titleColor
440494
if titleFontName != nil {
@@ -468,7 +522,7 @@ public class LGButton: UIControl {
468522
heightConstraint: leftImageHeightConstraint,
469523
widthValue: leftImageWidth,
470524
heightValue: leftImageHeight)
471-
leftIcon.isHidden = (leftImageSrc != nil || !availableFontIcons.contains(leftIconFontName))
525+
leftIcon.isHidden = (leftImageSrc != nil || !(SwiftIconFont.fonts[leftIconFontName] != nil))
472526
}
473527

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

486540
fileprivate func setupSpacings(){
@@ -512,44 +566,42 @@ public class LGButton: UIControl {
512566
setupBorderAndCorners()
513567
}
514568

569+
fileprivate func setupAlignment() {
570+
if leftAligned {
571+
titleLbl.textAlignment = .left
572+
} else if rightAligned {
573+
titleLbl.textAlignment = .right
574+
} else {
575+
titleLbl.textAlignment = .center
576+
}
577+
}
578+
515579
fileprivate func setupIcon(icon:UILabel, fontName:String, iconName:String, fontSize:CGFloat, color:UIColor){
516-
icon.isHidden = !availableFontIcons.contains(fontName)
517-
if !icon.isHidden {
580+
defer {
581+
setupBorderAndCorners()
582+
}
583+
if let iconFont = SwiftIconFont.fonts[fontName] {
584+
icon.isHidden = false
518585
icon.textColor = color
519-
switch fontName {
520-
case "fa":
521-
icon.font = UIFont.icon(from: .FontAwesome, ofSize: fontSize)
522-
icon.text = String.fontAwesomeIcon(iconName)
523-
break;
524-
case "io":
525-
icon.font = UIFont.icon(from: .Ionicon, ofSize: fontSize)
526-
icon.text = String.fontIonIcon(iconName)
527-
break;
528-
case "oc":
529-
icon.font = UIFont.icon(from: .Octicon, ofSize: fontSize)
530-
icon.text = String.fontOcticon(iconName)
531-
break;
532-
case "ic":
533-
icon.font = UIFont.icon(from: .Iconic, ofSize: fontSize)
534-
icon.text = String.fontIconicIcon(iconName)
535-
break;
536-
case "ma":
537-
icon.font = UIFont.icon(from: .MaterialIcon, ofSize: fontSize)
538-
icon.text = String.fontMaterialIcon(iconName.replacingOccurrences(of: "-", with: "."))
539-
break;
540-
case "ti":
541-
icon.font = UIFont.icon(from: .Themify, ofSize: fontSize)
542-
icon.text = String.fontThemifyIcon(iconName.replacingOccurrences(of: "-", with: "."))
543-
break;
544-
case "mi":
545-
icon.font = UIFont.icon(from: .MapIcon, ofSize: fontSize)
546-
icon.text = String.fontMapIcon(iconName.replacingOccurrences(of: "-", with: "."))
547-
break;
548-
default:
549-
break;
586+
icon.font = UIFont.icon(from: iconFont, ofSize: fontSize)
587+
if let iconStr = String.getIcon(from: iconFont, code: iconName) {
588+
icon.text = iconStr
589+
}else{
590+
let joind = ["-", ".", "_"]
591+
for left in joind {
592+
for right in joind {
593+
if left == right { continue }
594+
let code = iconName.replacingOccurrences(of: left, with: right)
595+
if let iconStr = String.getIcon(from: iconFont, code: code) {
596+
icon.text = iconStr
597+
return
598+
}
599+
}
600+
}
550601
}
602+
}else{
603+
icon.isHidden = true
551604
}
552-
setupBorderAndCorners()
553605
}
554606

555607
fileprivate func setupImage(imageView:UIImageView, image:UIImage?, color:UIColor?, widthConstraint:NSLayoutConstraint, heightConstraint:NSLayoutConstraint, widthValue:CGFloat, heightValue:CGFloat){
@@ -581,7 +633,7 @@ public class LGButton: UIControl {
581633
fileprivate func xibSetup() {
582634
rootView = loadViewFromNib()
583635
rootView.frame = bounds
584-
rootView.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
636+
rootView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
585637
addSubview(rootView)
586638
leadingLoadingConstraint.isActive = false
587639
trailingLoadingConstraint.isActive = false
@@ -613,7 +665,7 @@ public class LGButton: UIControl {
613665
touchAlpha = (pressed) ? .touched : .untouched
614666
}
615667
}
616-
668+
617669
override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
618670
pressed = true
619671
}
@@ -651,4 +703,12 @@ public class LGButton: UIControl {
651703
}
652704
}
653705
}
706+
707+
@IBAction func tapAction(_ sender: Any) {
708+
let shouldSendActions = pressed
709+
pressed = false
710+
if shouldSendActions{
711+
sendActions(for: .touchUpInside)
712+
}
713+
}
654714
}

0 commit comments

Comments
 (0)