GitXplorerGitXplorer
B

ImageAlertAction

public
33 stars
1 forks
3 issues

Commits

List of commits on branch main.
Verified
68ac9210dd83b68af7cb88cca252d3ced70046de

Finetunin' (#17)

BBasThomas committed 5 years ago
Unverified
4843b3004b788d078ba16118a2f1b33de0dc98be

Added support to display a checkmark with `isSelected` (#16)

ppedrommcarrasco committed 5 years ago
Verified
193cf42a1b28736fe6f64f58bb5bc880b4a52c4d

Update README.md (#15)

BBasThomas committed 5 years ago
Verified
e6823b6cf38d4e4e36ce8051d213e7f5b2b057b3

Add badge (#14)

BBasThomas committed 5 years ago
Verified
d7cdd91012312301b50aaa5d01278ddb794b021b

Swift 5.1 (#13)

BBasThomas committed 5 years ago
Verified
484a46b26125ef5c02dca70b1c2237a022adb8b8

Update LICENSE (#10)

BBasThomas committed 6 years ago

README

The README file for this repository.

Travis status

ImageAlertAction

ImageAlertAction is a UIAlertAction extension that adds support for an image in the action's button.

Action Sheet Alert

Example

To run the example project, clone the repository, and run pod install from the Example directory first.

Installation

ImageAlertAction is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ImageAlertAction'

Usage

Adding an image to a UIAlertAction

Create a UIAlertAction like you'd do normally, and pass an image to the image parameter. This will add the image on the left of the action's button.

let settings = UIAlertAction(
  title: "Settings",
  image: #imageLiteral(resourceName: "settings"),
  style: .default
)

Keeping the UIImage's original color

By default, the image provided will be treated as a template, and will be recolored based on the action's style. If you want to draw the original image, you can pass an image with an explicit rendering mode.

let settingsImage = #imageLiteral(resourceName: "settings").withRenderingMode(.alwaysOriginal) 
let settings = UIAlertAction(
  title: "Settings",
  image: settingsImage,
  style: .default
)

Accessing the added UIImage

As with the title and style, you can access the image set on the UIAlertAction.

let settings = UIAlertAction(
  title: "Settings",
  image: #imageLiteral(resourceName: "settings"),
  style: .default
)
settings.image // returns an optional UIImage

Adding a checkmark

You can also show a check mark on actions via isChecked.

let settings = UIAlertAction(
  title: "Settings",
  image: #imageLiteral(resourceName: "settings"),
  isChecked: true
  style: .default
)
settings.isChecked // returns a Bool

Presenting the UIAlertController

To present a UIAlertController containing the UIAlertAction, nothing changes.

let alertController = UIAlertController(
  title: "Title",
  message: "Message",
  preferredStyle: .actionSheet
)

let settings = UIAlertAction(
  title: "Settings",
  image: #imageLiteral(resourceName: "settings"),
  style: .default
)
alertController.addAction(settings)

present(alertController, animated: true)

Acknowledgements

License

ImageAlertAction is available under the MIT license. See the LICENSE file for more info.