Swiftpack.co - theoriginalbit/ShapeButton as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by theoriginalbit.
theoriginalbit/ShapeButton 1.1.1
A very simple library that provides a `UIButton` implementation that allows you to set stateful background colors.
⭐️ 2
🕓 8 weeks ago
iOS
.package(url: "https://github.com/theoriginalbit/ShapeButton.git", from: "1.1.1")

[!TIP] Did you know Apple introduced UIButton.Configuration in iOS 15?

Using the new Configuration API you can create a button like this library achieves. Simply do the following:

var initialConfig: UIButton.Configuration = .filled()
initialConfig.title = "Click me!"
initialConfig.buttonSize = .medium
// ...

let button = UIButton(configuration: initialConfig)
// ...

button.configurationUpdateHandler = { button in
    var currentConfig = button.configuration
    if button.isEnabled {
        currentConfig?.baseBackgroundColor = .systemBlue
    } else {
        currentConfig?.background.backgroundColor = .systemGray
    }
    // ...
}

ShapeButton

A very simple library that provides a UIButton implementation that allows you to create a button that looks like the Apple iOS Sketch library's 'Shape (Custom)' button.

The 'Shape (Custom)' button looks like:

The API is the same as with setting anything else that is state aware. The below code will produce a button like the image above.

import ShapeButton

// …
let myButton = ShapeButton(continuousCornerRadius: ShapeButton.cornerRadiusUseStandard)
myButton.setBackgroundColor(.systemBlue, for: .normal)
myButton.setTitleColor(.white, for: .normal)

// Stateful colors
myButton.setBackgroundColor(.systemGray, for: .disabled)
myButton.setTitleColor(.systemGray4, for: .disabled)

NOTE: Internally setBackgroundColor will generate a UIImage and call through to setBackgroundImage(_:for:) overriding any previous background image that may have been set.

Installation

Swift Package Manager

GitHub

link
Stars: 2
Last commit: 8 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics