Home

Awesome

QBIndicatorButton

Build Status Version License Platform

Custom of UIButton in Swift.

<img alt="Screenshot" src="https://github.com/sjc-bui/QBIndicatorButton/blob/master/Example/Screenshots/QBIndicatorButton.gif" width="300"/>

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Features

Requirements

Getting started

Storyboard Setup

Drag and drop UIButton into your Storyboard and set its class and module to QBIndicatorButton.

<img alt="custom class" src="https://github.com/sjc-bui/QBIndicatorButton/blob/master/Example/Screenshots/QBIndicatorButton-class.png" width="450"/>

Customize your button by setting properties from the Interface Builder.

<img alt="custom properties" src="https://github.com/sjc-bui/QBIndicatorButton/blob/master/Example/Screenshots/QBIndicatorButton-properties.png" width="450"/>

Code Setup

var loadingButton: QBIndicatorButton!
loadingButton = QBIndicatorButton(text: "Tap me",
                              textColor: UIColor.white,
                              font: UIFont.systemFont(ofSize: 18, weight: .semibold),
                              backgroundColor: .systemBlue,
                              cornerRadius: 4.0)

Button touch closure.

loadingButton.touch({ btn in
    // do stuff here
    btn.start()
}, for: .touchUpInside)

Show loading indicator.

loadingButton.start()
// or
loadingButton.start {
    // do something when start
    print("starting...")
}

Hide loading indicator.

loadingButton.stop()
// or
loadingButton.stop {
    // do something when stop
    print("stopping...")
}

Appearance

Supported appearance properties are:

PropertyTypeDescriptionDefault value
animatedScaleCGFloatAnimated scale1.0
animatedScaleDurationDoubleAnimated scale duration0.2
borderColorUIColorBorder colorUIColor.clear
borderWidthCGFloatBorder width0.0
cornerRadiusCGFloatCorner radius4.0
shadowColorUIColorThe color of the layer's shadowUIColor.clear
shadowOffsetCGSizeThe offset of the layer's shadow.zero
shadowOpacityFloatThe opacity of the layer's shadow0.0
shadowRadiusCGFloatThe blur radius of the layer's shadow0.0
gradientEnabledBoolEnable gradient background colorfalse
gradientStartColorUIColorStart of color gradientUIColor.clear
gradientEndColorUIColorEnd of color gradientUIColor.clear
gradientDirectionIntDirection of color gradient 0~71
activityIndicatorPositionIntPosition of activity indicator 0~21
titleFadeDurationDoubleButton title fade animated duration0.3
indicatorRotateDuration (v0.1.7)CFTimeIntervalThe activity indicator rotate duration1.0
indicatorStrokeColor (v0.1.7)UIColorCustom color of activity indicator.white
indicatorStrokeWidth (v0.1.7)CGFloatStroke width of activity indicator3.0

QBIndicatorButton also supported round every single corner of the button.

// round topLeft and topRight corner only
loadingButton.roundCorners(corners: [.topLeft, .topRight], radius: 20)
// or
// round all corner
loadingButton.roundCorners(corners: [.allCorners], radius: 20)

Predefined positions of activity indicator.

public enum IndicatorPosition: Int {
    case left   = 0
    case center = 1
    case right  = 2
}

Predefined directions for color gradient.

public enum GradientDirection: Int {
    case toTop         = 0
    case toRight       = 1
    case toBottom      = 2
    case toLeft        = 3
    case toTopRight    = 4
    case toTopLeft     = 5
    case toBottomRight = 6
    case toBottomLeft  = 7
}

Installation

QBIndicatorButton is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'QBIndicatorButton'

Contributing

MIT License

QBIndicatorButton is available under the MIT license. See the LICENSE file for more info.

Made with :heart: by sjc-bui.