GitXplorerGitXplorer
B

ImageAlertAction

public
33 stars
1 forks
3 issues

Commits

List of commits on branch main.
Verified
34596eed3e481604e0995d5cb7feedd795894dcd

Update to Swift 5 (#9)

BBasThomas committed 6 years ago
Verified
6f6caf290ba59bcfd97b0f80c2fc2cc7501f8046

Update CHANGELOG.md (#7)

BBasThomas committed 6 years ago
Verified
4f83f2bc9fb66468f1fcb29e64869355b5c07fb2

Add suport for Xcode 10 (#4)

BBasThomas committed 6 years ago
Verified
45abeb92a1dbb29b997c2c38e55c439f0df8b6ac

Make the example compileable (#6)

BBasThomas committed 6 years ago
Unverified
dce553499c0a81216806f80fa47777f2a125ab77

Run pod install

BBasThomas committed 7 years ago
Unverified
82041ef3f37bae81af808cc705c34cc55ad9480b

Revert "Update Cocoapods to 1.5.3"

BBasThomas committed 7 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.