Coder Social home page Coder Social logo

igor-palaguta / simplebutton Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aloco/simplebutton

0.0 2.0 0.0 1.19 MB

Simple UIButton subclass with additional state change animations (e.g. backgroundColor) and missing features

License: MIT License

Swift 97.09% Ruby 1.76% Objective-C 1.15%

simplebutton's Introduction

SimpleButton

Carthage compatible Build Status Swift 3

UIButton subclass with animated, state-aware attributes. Easy to subclass and configure! Full API docs

![Sample](Resources/example.gif)

Usage

Just create your own SimpleButton subclass and configure your button attributes by overriding configureButtonStyles.

class PrimaryButton: SimpleButton {
    override func configureButtonStyles() {
        super.configureButtonStyles()
		setBorderWidth(4.0, for: .normal)
        setBackgroundColor(UIColor(red: 52/255, green: 73/255, blue: 94/255, alpha: 1.0), for: .normal)
        setBackgroundColor(UIColor(red: 44/255, green: 62/255, blue: 80/255, alpha: 1.0), for: .highlighted)
        setBorderColor(UIColor(red: 44/255, green: 62/255, blue: 80/255, alpha: 1.0), for: .normal)
        setScale(0.98, for: .highlighted)
        setTitleColor(UIColor.whiteColor(), for: .normal)
    }
}

For usage in Interfacebuilder, just use your SimpleButton subclass as custom class for any UIButton element. All defined styles gets applied automatically.

You can also configure your button without a subclass directly inline.

let awesomeButton = SimpleButton(type: .custom)
awesomeButton.setBorderWidth(2.0, for: .normal)
awesomeButton.setBorderColor(UIColor.redColor(), for: .highlighted)
view.addSubview(awesomeButton)

Note that you should use UIButtonType.custom to avoid undesired effects.

Please checkout the example project for a detailed usage demo.

@IBDesignable

Have a look on DesignableButton subclass within the Example Project for @IBDesignable usage.

Animation

Each state change of SimpleButton animates by default. Sometimes you need to define which state transition should animate and which should happen immediately. Therefore you can control that behaviour with the animated and animationDuration parameters.

setBorderWidth(4.0, for: .normal, animated: true, animationDuration: 0.2)
setBorderWidth(8.0, for: .highlighted, animated: false)

This means, every state change to .normal animates the borderWidth to 4.0. Every state change to .highlighted changes instantly the borderWidth to 8.0 without animation.

Loading state

SimpleButton has a custom loading state. You can toggle this state by setting simpleButton.isLoading. The button shows an UIActivityIndicator instead of the title when adding the loading state.

simpleButton.setCornerRadius(20, for: SimpleButtonControlState.loading)
simpleButton.isLoading = true

If you don´t like the default loading indicator, you can set your own UIView by doing

simpleButton.loadingView = CustomAwesomeLoadingView()

Configurable attributes

Take a look at the Setter for state attributes section of the API Docs

Installation

Note that SimpleButton is written in swift 3 and may not be compatible with previous versions of swift.

Carthage

Add the following line to your Cartfile.

github "aloco/SimpleButton" ~> 3.0

Then run carthage update.

Manually

Just drag and drop the SimpleButton.swift file into your project.

Contributing

  • Create something awesome, make the code better, add some functionality, whatever (this is the hardest part).
  • Fork it
  • Create new branch to make your changes
  • Commit all your changes to your branch
  • Submit a pull request

simplebutton's People

Contributors

aloco avatar igor-palaguta avatar aschuch avatar zettlunic avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.