Skip to content

πŸ”˜ Small library for UIButton and UIBarButtonItems with a selected state like a toggle switch

License

Notifications You must be signed in to change notification settings

Tomn94/TNRecessedButton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RecessedButton

Version Code Platform Contributors Licence

Example 1 normal Example 1 selected

Example 2 normal Example 2 selected

Description

RecessedButton avoids reimplementing all the time a UIButton acting like a toggle switch.
RecessedBarButton provides this button for UIBarButtonItem in Navigation Bars.

When tapped, it enters selected mode, and has a rounded rect background.

Installation

Just import the file TNRecessedButton.swift in your project.

Usage

/* 1. Create the button */
let button = RecessedButton()

/* 2. Customize it like any button */
button.setTitle("Button", for: .normal)
button.setImage(anIcon,   for: .normal)

/* 3. Selected state can be customized as well */
button.setTitle("Selected",    for: .selected)
button.setImage(aSelectedIcon, for: .selected)

/* 4. If you really need,
      you can adjust the corner radius when selected */
button.layer.cornerRadius = 7
button.clipsToBounds = true

/* 5. To use in a Navigation Bar */
navigationItem.rightBarButtonItem = RecessedBarButton(button: button)

Using icons

Take a look at the illustrations on top of this README.
Notice the background of selected (i) icon is not a square. This is awful.
Whereas the background of Tramigo's time icon is (second example, red background).

Make sure you have a square as well.

To do so for your icon-only buttons, play with their (content, image, title) insets.
Alternatively, you can ajdust the width of your PNG icon file by adding extra transparent pixels.

Example

An Xcode project demonstrating RecessedButton is included under Example folder.

Requirements

  • Swift 4
  • iOS 9 or later

Release notes

v1.0

Initial version

Evolution

  • RecessedBarButton background and icon don't resize on iPhone landscape
  • Background color could be customized
  • Background corner radius as well

Author

Written by Thomas Naudet, feel free to give me your feedback, or even to tell me you're using this πŸ˜ƒ.

Licence

Available under the MIT license.
See the LICENSE file for more info.

About

πŸ”˜ Small library for UIButton and UIBarButtonItems with a selected state like a toggle switch

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages