Skip to content

Commit

Permalink
Started implementation loader
Browse files Browse the repository at this point in the history
  • Loading branch information
pmusolino committed Jun 15, 2017
1 parent a5db98e commit 0289a5e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
5 changes: 4 additions & 1 deletion PMSuperButtonSample/Base.lproj/Main.storyboard
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand Down Expand Up @@ -71,6 +71,9 @@
<constraint firstItem="Lbp-GZ-boJ" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="fBf-MH-Cp6"/>
</constraints>
</view>
<connections>
<outlet property="firstButton" destination="Mas-24-YKL" id="dKZ-Ip-4ls"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
Expand Down
11 changes: 11 additions & 0 deletions PMSuperButtonSample/ViewController.swift
Expand Up @@ -11,9 +11,20 @@ import PMSuperButton

class ViewController: UIViewController {

@IBOutlet weak var firstButton: PMSuperButton!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.


}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
firstButton.touchUpInside {
self.firstButton.showLoader()
}
}

override func didReceiveMemoryWarning() {
Expand Down
39 changes: 28 additions & 11 deletions Sources/PMSuperButton.swift
Expand Up @@ -2,14 +2,14 @@
// PMSuperButton.swift
// PMSuperButton
//
// Created by Paolo Musolino on {TODAY}.
// Created by Paolo Musolino on 14/06/17.
// Copyright 漏 2017 PMSuperButton. All rights reserved.
//

import UIKit

@IBDesignable
class PMSuperButton: UIButton {
open class PMSuperButton: UIButton {

//MARK: Appearance
@IBInspectable var borderColor: UIColor = UIColor.clear{
Expand Down Expand Up @@ -48,7 +48,6 @@ class PMSuperButton: UIButton {
}
}


//MARK: Toggle
@IBInspectable var toggleButton: Bool = false{
didSet{
Expand All @@ -62,33 +61,51 @@ class PMSuperButton: UIButton {
@IBInspectable var uncheckedImage: UIImage = UIImage()
@IBInspectable var checkedImage: UIImage = UIImage()

//Image inside UIButton
//MARK: Image UIButton content mode
@IBInspectable var imageContentMode: Int = UIViewContentMode.scaleToFill.rawValue{
didSet{
imageView?.contentMode = UIViewContentMode(rawValue: imageContentMode) ?? .scaleToFill
}
}

override func layoutSubviews() {
func buttonChecked(sender:AnyObject){
self.isSelected = !self.isSelected
}

//MARK: Interface Builder
override open func layoutSubviews() {
super.layoutSubviews()
self.addTarget(self, action: #selector(tapped), for: .touchUpInside)
}

override func prepareForInterfaceBuilder() {
}

func buttonChecked(sender:AnyObject){
self.isSelected = !self.isSelected
override open func prepareForInterfaceBuilder() {
}

//MARK: Action Closure
private var action: (() -> Void)?

func touchUpInside(action: (() -> Void)? = nil){
open func touchUpInside(action: (() -> Void)? = nil){
self.action = action
}

func tapped(sender: PMSuperButton) {
self.action?()
}

//MARK: Loading
let indicator: UIActivityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)

open func showLoader(){
indicator.center = CGPoint(x: self.bounds.size.width/2, y: self.bounds.size.height/2)
indicator.startAnimating()
UIView.transition(with: self, duration: 0.5, options: .curveEaseOut, animations: {

}) { (finished) in
self.addSubview(self.indicator)
}
}

open func hideLoader(){
indicator.removeFromSuperview()
}
}
2 changes: 1 addition & 1 deletion Tests/PMSuperButtonTests/PMSuperButtonTests.swift
Expand Up @@ -2,7 +2,7 @@
// PMSuperButtonTests.swift
// PMSuperButton
//
// Created by Paolo Musolino on {TODAY}.
// Created by Paolo Musolino on 14/06/17.
// Copyright 漏 2017 PMSuperButton. All rights reserved.
//

Expand Down

0 comments on commit 0289a5e

Please sign in to comment.