Skip to content

Latest commit

History

History
95 lines (56 loc) 路 2.72 KB

README.md

File metadata and controls

95 lines (56 loc) 路 2.72 KB

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.