Simple and customizable button in Swift

Overview

SwiftyButton

Maintainer(s): @nickm01 @pmacro @aryamansharda

Simple and customizable button in Swift.

Carthage compatible

Installation

Cocoapods

pod 'SwiftyButton'

Carthage

github 'TakeScoop/SwiftyButton'

Usage

Flat Button

let button = FlatButton()
button.color = .cyan
button.highlightedColor = .blue
button.cornerRadius  = 5

Pressable Button

let button = PressableButton()
button.colors = .init(button: .cyan, shadow: .blue)
button.shadowHeight = 5
button.cornerRadius = 5

All Properties

Here is a list of all the properties that you can modify. Those are all editable directly from Interface Builder. See FlatButton.Defaults or PressableButton.Defaults to set defaults for those properties.

FlatButton

button.color = .cyan
button.highlightedColor = .cyan
button.selectedColor = .blue
button.disabledButtonColor = .gray
button.cornerRadius = 8

PressableButton

button.colors = .init(button: .cyan, shadow: .blue)
button.disabledColors = .init(button: .gray, shadow: .darkGray)
button.shadowHeight = 10
button.cornerRadius = 8
button.depth = 0.5 // In percentage of shadowHeight

Interface Builder (Storyboard/XIB)

Add a UIButton as usual, then:

  • Modify the underlying class to FlatButton/PressableButton, and that the module is set to SwiftyButton
  • Make sure that the button type is set to Custom

Defaults

You can set defaults that will be applied for any new instance of SwiftyButton by modifying the FlatButton.Defaults or PressableButton.Defaults structure:

FlatButton.Defaults.color = .cyan
PressableButton.Defaults.cornerRadius = 8
...

Custom Content

Use CustomPressableButton to add custom content in a Swifty Button.

This is a subclass of SwiftyButton that exposes a content view that moves when the button state changes. All you have to do is add your views inside button.contentView and setup layout constraints relative to this view.

Install

pod `SwiftyButton/CustomContent`

Usage

Here is how you would create a button similar to the one above (here we used PureLayout for constraints):

let button = CustomPressableButton()

let indicator = UIActivityIndicatorView(activityIndicatorStyle: .white)
button.contentView.addSubview(indicator)
indicator.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 10, left: 15, bottom: 10, right: 0), excludingEdge: .right)
indicator.startAnimating()

let label = UILabel()
button.contentView.addSubview(label)
label.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 10), excludingEdge: .left)
label.autoPinEdge(.left, to: .right, of: indicator, withOffset: 10)
label.text = "Loading..."
label.textColor = .white

Known limitations

  • PressableButton only works with plain colors (no alpha / transparency) because of the way its background image is rendered. See #2
  • PressableButton manages title and image insets automatically (titleEdgeInsets and imageEdgeInsets). See #5
    • User-specified inset values for top and bottom will be overridden.
    • You may specify inset values for left and right.

More examples

Look at the Examples folder to see more button examples.

Contribute

Publishing a new version

Here's an example of a version bump: bump to 0.8.0.

Replace NEW_VERSION with the version you're about to publish.

  • Checkout the master branch and ensure it's up-to-date.
  • Open SwiftyButton.xcworkspace and edit settings for the SwiftyButton target. Change the target version to NEW_VERSION.
  • Open CHANGELOG.md and add a new section [NEW_VERSION]. At the bottom of the document, copy a version anchor and link to the new version tag (which we'll create later). Insert a new empty [master] section on top.
  • Open SwiftyButton.podspec and edit s.version to NEW_VERSION.
  • Commit your changes as Bump to NEW_VERSION.
  • Create a new git tag named NEW_VERSION and push your commit + tag to Github.
  • Push the new pod version with $ pod trunk push ./

License

This project is copyrighted under the MIT license. Complete license can be found here: https://github.com/TakeScoop/SwiftyButton/blob/master/LICENSE

Credits

Comments
  • Xib / Storyboard visualization is broken (reproducible)

    Xib / Storyboard visualization is broken (reproducible)

    Hi,

    First of all, this is an awesome library, thank you so much for your work.

    I'm having an issue which I've confirmed on a clean project.

    When adding a SwiftyButton to a xib/storyboard, all auto-layout behavior becomes broken for the screen on the xib editor. Additionally, the SwiftyButton is not rendered as it will appear on the screen (it continues to look like a standard UIButton).

    During runtime, everything still works fine; only the xib/storyboard editor is broken.

    I'm also getting these 2 errors:

    file:///Users/ataibarkai/Local-Git-Repos/Experiments/SwiftyButtonExperiment/SwiftyButtonExperiment/Base.lproj/Main.storyboard: error: IB Designables: Failed to update auto layout status: dlopen(SwiftyButton.framework, 1): Library not loaded: @rpath/PureLayout.framework/PureLayout
      Referenced from: SwiftyButton.framework
      Reason: image not found
    
    file:///Users/ataibarkai/Local-Git-Repos/Experiments/SwiftyButtonExperiment/SwiftyButtonExperiment/Base.lproj/Main.storyboard: error: IB Designables: Failed to render instance of SwiftyButton: dlopen(SwiftyButton.framework, 1): Library not loaded: @rpath/PureLayout.framework/PureLayout
      Referenced from: SwiftyButton.framework
      Reason: image not found
    
    

    When selecting the module for the custom class on storyboard, I've tried both SwiftyButton (autocompleted by Xcode when selecting SwiftyButton as the class), and a module with a name identical to my project/target name.

    This is reproducible on a clean project, installing SwiftyButton using cocoapods (v1.0.1).

    opened by ataibarkai 11
  • SwiftyButton does not work with Carthage

    SwiftyButton does not work with Carthage

    $ carthage update --platform iOS
    *** Fetching SwiftyButton
    *** Fetching SwiftyJSON
    *** Fetching Alamofire
    *** Checking out Alamofire at "4.3.0"
    *** Checking out SwiftyButton at "0.6.0"
    *** Downloading SwiftyJSON.framework binary at "3.1.4"
    *** xcodebuild output can be found in /var/folders/xl/gxvzy0ws6q3bs_p2q2k69mg00000gn/T/carthage-xcodebuild.CKTxod.log
    *** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
    *** Skipped building SwiftyButton due to the error:
    Dependency "SwiftyButton" has no shared framework schemes for any of the platforms: iOS
    
    If you believe this to be an error, please file an issue with the maintainers at Optional("https://github.com/TakeScoop/SwiftyButton/issues/new")
    
    bug 
    opened by rnitame 8
  • Flat button not visible on iPhone 5

    Flat button not visible on iPhone 5

    Awesome Library! Thanks. It looks like the Button disappears when launched on an iPhone 5/5s. Is this a bug of some kind? Or am I doing something wrong. Works well on iPhone 6 and greater.

    opened by erhiesfeka 5
  • Bottom of button text cut off when using Font Awesome

    Bottom of button text cut off when using Font Awesome

    I'm new to iOS programming. I've noticed that if I have a prefix containing the letters "g", "p", etc, the bottom part of the text is cut off when I use font awesome icons by Vaberer's Font-Awesome-Swift library.

    Imgur

    Do you have any hints to what might be causing this problem?

    opened by squeeish 5
  • Can't create button in IB

    Can't create button in IB

    When trying to create a button in IB following the instructions on the README I get the following error:

    file:///Users/$USER/Path/To/My/Project/Base.lproj/Main.storyboard: warning: IB Designables: Using class UIButton for object with custom class because the class PressableButton does not exist
    

    I installed via Coccoapods pod 'SwiftyButton' and when typing the buttons class in IB it does autocomplete it and offers it as an option in the list of choices.

    screen shot 2017-02-06 at 2 44 43 pm

    Any help is appreciated, thanks!

    EDIT: To be clear, I did set the button type to custom.

    opened by perryprog 3
  • Put Purelayout out of this library.

    Put Purelayout out of this library.

    Such an awesome library, but wasted for fancy inclusion of another library that adds no value and can be coded with NSLayoutContrstaints. Please keep the code clean. The point of libraries are to keep third party dependency as less as possible.

    The obvious answer would be, no you don't have to use my library, find another one or write it yourself. Well thats what I am doing. But just to make my point clear, just coz it your preference to use autolayout with PureLayout forces the users of this library to have that dependency. It is NOT required.

    opened by Joker666 2
  • Update background performance improvement.

    Update background performance improvement.

    Not the background of FlatButton is only updated inside the draw method. This had a negative impact on the performance when the properties of the button were changed multiple times within the same code block.

    opened by drastawi 0
  • Configure WhiteSource Bolt for GitHub

    Configure WhiteSource Bolt for GitHub

    Welcome to WhiteSource Bolt for GitHub! This is an onboarding PR to help you understand and configure settings before WhiteSource starts scanning your repository for security vulnerabilities.

    :vertical_traffic_light: WhiteSource Bolt for GitHub will start scanning your repository only once you merge this Pull Request. To disable WhiteSource Bolt for GitHub, simply close this Pull Request.


    What to Expect

    This PR contains a '.whitesource' configuration file which can be customized to your needs. If no changes were applied to this file, WhiteSource Bolt for GitHub will use the default configuration.

    Before merging this PR, Make sure the Issues tab is enabled. Once you merge this PR, WhiteSource Bolt for GitHub will scan your repository and create a GitHub Issue for every vulnerability detected in your repository.

    If you do not want a GitHub Issue to be created for each detected vulnerability, you can edit the '.whitesource' file and set the 'minSeverityLevel' parameter to 'NONE'.


    :question: Got questions? Check out WhiteSource Bolt for GitHub docs. If you need any further assistance then you can also request help here.

    opened by mend-bolt-for-github[bot] 0
  • Configure Renovate

    Configure Renovate

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • .ruby-version (ruby-version)

    Configuration Summary

    Based on the default config's presets, Renovate will:

    • Start dependency updates only once this onboarding PR is merged
    • Enable Renovate Dependency Dashboard creation.
    • If Renovate detects semantic commits, it will use semantic commit type fix for dependencies and chore for all others.
    • Ignore node_modules, bower_components, vendor and various test/tests directories.
    • Autodetect whether to pin dependencies or maintain ranges.
    • Rate limit PR creation to a maximum of two per hour.
    • Limit to maximum 10 open PRs at any time.
    • Group known monorepo packages together.
    • Use curated list of recommended non-monorepo package groupings.
    • A collection of workarounds for known problems with packages.

    🔡 Would you like to change the way Renovate is upgrading your dependencies? Simply edit the renovate.json in this branch with your custom config and the list of Pull Requests in the "What to Expect" section below will be updated the next time Renovate runs.


    What to Expect

    With your current configuration, Renovate will create 2 Pull Requests:

    Update dependency ruby to v2.7.6
    • Schedule: ["at any time"]
    • Branch name: renovate/ruby-2.x
    • Merge into: master
    • Upgrade ruby to 2.7.6
    Update dependency ruby to v3
    • Schedule: ["at any time"]
    • Branch name: renovate/ruby-3.x
    • Merge into: master
    • Upgrade ruby to 3.1.2

    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
  • The image does not move with the button when I press a PressableButton

    The image does not move with the button when I press a PressableButton

    To reproduce this, put a PressableButton on the storyboard, set its image to some image and text to "". Now try to press the button. The button will look like as if it's been pressed, but the image stays at the same position. This looks very unnatural.

    bug 
    opened by Sweeper777 3
Releases(0.8.2)
Owner
Scoop
Scoop
Simple and customizable button in Swift

SwiftyButton Maintainer(s): @nickm01 @pmacro @aryamansharda Simple and customizable button in Swift. Installation Cocoapods pod 'SwiftyButton' Cartha

Scoop 542 Dec 13, 2022
Customizable and easy to use expandable button in Swift.

ExpandableButton Requirements iOS 9.0+ Installation CocoaPods: Add the following line to your Podfile: pod 'ExpandableButton' #for swift less than 4.

Dmytro Mishchenko 98 Dec 5, 2022
Easily customizable floating button menu created with SwiftUI

FloatingButton Easily customizable floating button menu created with SwiftUI We are a development agency building phenomenal apps. Usage Create main b

Exyte 715 Dec 30, 2022
Floaty is simple floating action button for iOS.

Floaty is simple floating action button for iOS. (formerly KCFloatingActionButton) Why change the name? Follow the swift naming convention. KCF

Lee Sun-Hyoup 1.5k Jan 7, 2023
Animated Play and Pause Button written in Swift, using CALayer, CAKeyframeAnimation.

AnimatablePlayButton Animated Play and Pause Button written in Swift, using CALayer, CAKeyframeAnimation. features Only using CAShapeLayer, CAKeyframe

keishi suzuki 77 Jun 10, 2021
IGStoryButtonKit provides an easy-to-use button with rich animation and multiple way inspired by instagram story/stories.

Introduction Have you ever seen UI like instagram story, haven't you? Actually, features like instagram story have been implemented in many applicatio

mutation 34 Nov 8, 2022
Interactive and fully animated Material Design button for iOS developers.

WYMaterialButton Inspired by Google Material Design, written purely in Swift 3. WYMaterialButton implemented Material Design on iOS and add more dynam

Yu Wang 76 Oct 7, 2022
Cute Animated Button written in Swift.

DOFavoriteButton Cute Animated Button written in Swift. It could be just right for favorite buttons! Requirements iOS 7.0+ Swift 1.2 Installation Cart

Daiki Okumura 3.6k Dec 29, 2022
iOS Pod for a Soft UI (Neumorphic) Button for UIKit written in Swift

iOS Pod for a Soft UI (Neumorphic) Button for UIKit written in Swift

Pallav Agarwal 21 Oct 23, 2022
LTHRadioButton - A radio button with a pretty animation

LTHRadioButton Slightly inspired by Google's material radio button. The clip below has 3 sections: full speed, 25% and 10%, but after converting it to

Roland Leth 368 Dec 16, 2022
Multiple state tap-to-toggle UIButton (like old camera flash button)

Multiple State Toggle UIButton A UIButton subclass that implements tap-to-toggle button text. (Like the camera flash and timer buttons) Usage Just cre

Yonat Sharon 83 Oct 11, 2022
Lickable-Button We made the buttons on the screen look so good you'll want to lick them

Lickable-Button We made the buttons on the screen look so good you'll want to lick them. - Steve Jobs A little SwiftUI button project at WWDC 2021 Lic

Nate Thompson 14 Dec 29, 2021
Craft that perfect SwiftUI button effect 👌🏼

buttoncraft (SwiftUI 3.0 App) Experimenting with SwiftUI 3.0 whilst creating a practical app to craft that perfect button style. ✈️ Testflight https:/

An Trinh 188 Dec 28, 2022
Custom loading button with progress swiftui

CustomLoadingButton Simple Custom Loading Progress Button for SwiftUI Version 1.0.0 This version requires Xcode 11+ SwiftUI iOS 13+ macOS 10.15+ Insta

Tariqul 1 Dec 14, 2022
An open-source library to use with SwiftUI, It allows you to create Floating menu action button.

Floating Menu Action Button Example Overview This is an open-source library to use with SwiftUI. It allows you to create Floating menu action button. Ins

ugo 3 Aug 19, 2022
iOS 7-style bouncy button.

SSBouncyButton SSBouncyButton is simple button UI component with iOS 7-style bouncy animation. Take A Look Try It! pod 'SSBouncyButton', '~> 1.0' Use

StyleShare 310 Dec 15, 2022
Flat button with 9 different states using POP

VBFPopFlatButton Flat button with 21 different states and 2 types animated using pop. These are some examples of both types in different states: And h

Victor Baro 3.1k Nov 30, 2022
Flat design pressable button for iOS developers.

HTPressableButton HTPressableButton is designed for iOS developers to be able to spend time developing ideas, not building basic buttons. These stylis

Famolus 859 Dec 12, 2022
Material Design Floating Action Button in liquid state

LiquidFloatingActionButton [] (https://github.com/Carthage/Carthage) LiquidFloatingActionButton is floating action button component of material design

Takuma Yoshida 3.8k Dec 29, 2022