Swiftpack.co -  gabrieloc/roundrect as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
gabrieloc/roundrect
Conveniences for programmatically generating image assets and styling UIButton
.package(url: "https://github.com/gabrieloc/roundrect.git", from: "v1.3.1")

roundrect

Conveniences for programmatically generating image assets and styling UIButton.

Creating Images

The conveniences in ImageGeneration.swift allow images to be generated from a view, or given various style properties like fill, stroke, corner radius, etc. For example, to create a 3px/3px image with a 1px blue stroke and a single red fill:

let image = UIImage(
  fill: .red,
  stroke: (
    color: .blue, 
    width: 1
  )
)

This image can be made resizable and applied to a UIButton, but since there is a lot of busywork associated with handling all the different states a button can have, the conveniences in ButtonStyle can be used instead. A combination of a button Style (eg. filled vs bordered) and Theme (eg. light or dark) can be provided when creating or modifying an existing UIButton:

let button = UIButton(
  style: .filled(
    cornerRadius: 8
  )
)

This will yield a button with a tintable fill and a corner radius of 8.

API exists for an explicit theme to be provided, but it's marked as obsolete as of iOS13 in favour of light/dark mode provided by UIInterfaceStyle.

Contributing

Snapshot tests are recorded with the iOS 14.4 iPhone 12 simulator using the Swift Snapshot Testing library.

Examples

<iOS13 variations with explicit themes

iOS13+ variations for light and dark mode

light dark

GitHub

link
Stars: 149
Last commit: 6 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

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