A Custom UIButton with Centralised Styling and common styles available in Interface Builder

Overview

DesignableButton

DesignableButton Language: Swift 4.0

alt demo

DesignableButton is a UIButton subclass that uses a centralised and reusable styling. In InterfaceBuilder, drag and drop a DesignableButton, choose your style and its applied instantly in InterfaceBuilder

Features

  • One centralised class to define you main button styles so they can be reused
  • Different styles for different button states: Normal/Selected/Disabled
  • The centralised styles can be set in IB (no more IBOutlets needed for programatical styling)
  • View the style in IB in realtime. Even changing button to selected state will update IB
  • Individual buttons can override their centralised styles in IB
  • Rounded corners and borders are easy with DesignableButton
  • Buttons with an image above text are easy with DesignableButton

How to install

Add this to your CocoaPods Podfile. Note the IH prefix

pod 'IHDesignableButton'

How to use

Create an DesignableButton+Styles.swift extension file in your project

import UIKit
import IHDesignableButton // if DesignableButton is in CocoaPod
extension DesignableButton {
    
    override open func prepareForInterfaceBuilder() {
        super.prepareForInterfaceBuilder()
        
        DesignableButton.setDesignableStyles(isInterfaceBuilder: true)
    }
    
    static func setDesignableStyles(isInterfaceBuilder: Bool = false) {
        
        // example style
        DesignableButton.setStyle(style: { (designableButton: DesignableButton) -> Void in
            if designableButton.isHighlighted || designableButton.isSelected {
                // replace this with your style for selected/highlighted states
                designableButton.setTitleColor(designableButton.customTextColor ?? UIColor.white, for: UIControlState())
                designableButton.backgroundColor = designableButton.selectedColor ?? UIColor.red
                designableButton.layer.borderColor = designableButton.selectedColor?.cgColor ?? UIColor.red.cgColor
                designableButton.layer.borderWidth = designableButton.borderWidth ?? 0
            } else if designableButton.isEnabled {
                // replace this with your style for the normal state
                designableButton.setTitleColor(designableButton.customTextColor ?? UIColor.white, for: UIControlState())
                designableButton.backgroundColor = designableButton.defaultColor ?? UIColor.blue
                designableButton.layer.borderColor = designableButton.defaultColor?.cgColor ?? UIColor.blue.cgColor
                designableButton.layer.borderWidth = designableButton.borderWidth ?? 0
            }
            else {
                // replace this with your style for the disabled state
                designableButton.setTitleColor(designableButton.customTextColor ?? UIColor.lightGray, for: UIControlState())
                designableButton.backgroundColor = designableButton.disabledColor ?? UIColor.lightGray()
                designableButton.layer.borderColor = designableButton.borderColor?.cgColor ??  UIColor.gray.cgColor
                designableButton.layer.borderWidth = designableButton.borderWidth ?? 1
            }
            
            // replace this with your style for all states
            designableButton.layer.cornerRadius = designableButton.cornerRadius ?? 12
            
            designableButton.setTitle(designableButton.titleLabel?.text, for: .normal)
            
        }, for: "primary") // this is the name/key of your style
    }
}

In the setDesignableStyles() method you can call DesignableButton.setStyle() to create a new style. Most projects will only need a few button styles

In you AppDelegate's application(_ , didFinishLaunchingWithOptions() call DesignableButton.setDesignableStyles()

Now in Interface Builder, drag a UIButton onto a view

Change the class to DesignableButton and the module to IHDesignableButton

Change the button type from System to Custom

Set the Button Style to "primary" or any other button style you're created

Half price for a limited time only :)

A Codable extension to decode arrays and to catch & log all decoding failures https://github.com/IdleHandsApps/SafeDecoder

An elegant solution for keeping views visible when the keyboard is being shown https://github.com/IdleHandsApps/IHKeyboardAvoiding

A fully automatic status bar overlay for No Internet Connection messages https://github.com/IdleHandsApps/StatusBarOverlay

Author

It'd be great to hear about any cool apps that are using DesignableButton

License

Distributed under the MIT License

You might also like...
Customizable and easy to use expandable button in Swift.
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.

IGStoryButtonKit provides an easy-to-use button with rich animation and multiple way inspired by instagram story/stories.
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

Simple and customizable button in Swift
Simple and customizable button in Swift

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

Animated Play and Pause Button written in Swift, using CALayer, CAKeyframeAnimation.
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

Interactive and fully animated Material Design button for iOS developers.
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

TTopImageBottomLabelButton is a simple and flexible UI component fully written in Swift
TTopImageBottomLabelButton is a simple and flexible UI component fully written in Swift

TTopImageBottomLabelButton is a simple and flexible UI component fully written in Swift. TTopImageBottomLabelButton is developed to help programmers create a button with top image and bottom title quickly without having to write many lines of codes.

It is a highly configurable iOS library which allows easy styling with built in styles as well as extra header and footer views so that you can make extremely unique alerts and action sheets.
It is a highly configurable iOS library which allows easy styling with built in styles as well as extra header and footer views so that you can make extremely unique alerts and action sheets.

 CFAlertViewController CFAlertViewController is a library that helps you display and customise Alerts, Action Sheets, and Notifications on iPad and i

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

Custom Field component with validation for creating easier form-like UI from interface builder.
Custom Field component with validation for creating easier form-like UI from interface builder.

#YALField Custom Field component with validation for creating easier form-like UI from interface builder. ##Example Project To run the example project

Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.
Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.

Design and prototype customized UI, interaction, navigation, transition and animation for App Store ready Apps in Interface Builder with IBAnimatable.

PJFDataSource is a small library that provides a simple, clean architecture for your app to manage its data sources while providing a consistent user interface for common content states (i.e. loading, loaded, empty, and error).
PJFDataSource is a small library that provides a simple, clean architecture for your app to manage its data sources while providing a consistent user interface for common content states (i.e. loading, loaded, empty, and error).

PJFDataSource PJFDataSource is a small library that provides a simple, clean architecture for your app to manage its data sources while providing a co

Kodi is an award-winning free and open source home theater/media center software and entertainment hub for digital media. With its beautiful interface and powerful skinning engine, it's available for Android, BSD, Linux, macOS, iOS and Windows.
Introducing with Xcode Storyboard and Interface Builder

I-am-rich Introducing with Xcode Storyboard and Interface Builder Introducing wi

Setup your class structure in Xcode Interface Builder and save() in Parse Server.
Setup your class structure in Xcode Interface Builder and save() in Parse Server.

ISParseBind With ISParseBind you can save, update and query PFObjects using the power of Xcode Interface Builder resources. https://www.youtube.com/wa

AttributedString Markdown initializer with custom styling
AttributedString Markdown initializer with custom styling

AttributedString Markdown initializer with custom styling AttributedString in iOS 15 and macOS 12 comes with a Markdown initializer. But: There is no

Custom UIButton effect inspired by Google Material Design
Custom UIButton effect inspired by Google Material Design

ZFRippleButton iOS Custom UIButton effect inspired by Google Material Design written in Swift Usage Set the UIButton class in Nib to ZFRippleButton or

Localize your views directly in Interface Builder with IBLocalizable
Localize your views directly in Interface Builder with IBLocalizable

Localize your views easily in Interface Builder with IBLocalizable. With IBLocalizable, you can localize your views in Interface Builder easily. Simpl

Comments
  • Update to Swift 4.2 + Fix .swift-version file deprecation

    Update to Swift 4.2 + Fix .swift-version file deprecation

    Hi! Thanks for the great library. While using this library in my own project, my project was failing to build due to some cocoapods changes (highlighted below).

    This pull request does the following:

    1. Remove the .swift-version file and replace it with a s.swift_version in the Podspec file for the following reason:
      • CocoaPods 1.4.0+ doesn't fully respect .swift-version files like previous installations; installed pods will attempt to be built using your project's explicit swift version.
      • In my case, this was Swift 4.2, and the project failed to build since multiple renames have occurred from Swift 4.0 -> 4.2.
    2. Update the files to be compatible with Swift 4.2 to keep up with Swift's constantly evolving/deprecating nature

    This pull request does not do the following:

    • Update the podspec file with a new version number or create any new tags-- you'll have to do this part if this PR is merged
    opened by Chris-Perkins 0
Owner
Idle Hands Apps
c/- Fraser Scott-Morrison
Idle Hands Apps
A small and flexible (well documented) UIButton subclass with animated loading progress, and completion animation.

ButtonProgressBar-iOS Example For LIVE PREVIEW on Appetize in your browser itself, click here. To run the example project, clone the repo, and run pod

Pushkar Sharma 566 Dec 9, 2022
UIButton sublass for loading and transition animation.

TransitionButton Concept Source: Dribbble Preview Expand animation: Shake animation: Example To run the example project, clone the repo, then open the

null 1.4k Dec 25, 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
🔥 PMSuperButton is a powerful UIButton coming from the countryside, but with super powers! 😎

PMSuperButton is a powerful UIButton coming from the countryside, but with super powers! ?? An easy way to create custom and complex buttons with cust

Paolo Musolino 720 Nov 17, 2022
UIButton-based view with fade in/out animation features

JTFadingInfoView Overview JTFadingInfoView is google's material design like notification view with smooth fade in/out animation features, based on UIB

Junichi Tsurukawa 129 Mar 19, 2022
A fully customisable swift subclass on UIButton which allows you to create beautiful buttons without writing any line of code.

JSButton Demo $ pod try JSButton ...or clone this repo and build and run/test the JSButton project in Xcode to see JSButton in action. If you don't ha

Jogendra 12 May 9, 2022
Full-featured IBDesignable UIButton class

SpicyButton Full-featured IBDesignable UIButton class Installation Add the following to your project's Podfile: pod 'SpicyButton' Usage You can easily

Luke Crum 2 Sep 6, 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
ProgressButton - Custom button class that displays a progress bar around it to gauge

ProgressButton Check it out To run the example project, clone the repo, and open the 'Example/Example.xcodeproj' file. Requirements This component is

Guilherme Moura 116 May 29, 2022
Customizable download button with progress and transition animations. It is based on Apple's App Store download button.

AHDownloadButton is a customizable download button similar to the download button in the latest version of Apple's App Store app (since iOS 11). It fe

Amer Hukić 465 Dec 24, 2022