Latest 2.0.0
Homepage https://github.com/BasThomas/ImageAlertAction
License MIT
Platforms ios 8.0
Frameworks UIKit
Authors

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

Action SheetAlert

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

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.

Latest podspec

{
    "name": "ImageAlertAction",
    "version": "2.0.0",
    "summary": "Image support for UIAlertAction",
    "description": "ImageAlertAction adds image support to UIAlertAction.nUse this to visually convey an action's purpose.",
    "homepage": "https://github.com/BasThomas/ImageAlertAction",
    "screenshots": [
        "https://raw.githubusercontent.com/BasThomas/ImageAlertAction/master/assets/alert.png",
        "https://raw.githubusercontent.com/BasThomas/ImageAlertAction/master/assets/actionsheet.png"
    ],
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Bas Broek": "[email protected]"
    },
    "source": {
        "git": "https://github.com/BasThomas/ImageAlertAction.git",
        "tag": "2.0.0"
    },
    "social_media_url": "https://twitter.com/basthomas",
    "platforms": {
        "ios": "8.0"
    },
    "swift_version": "4.2",
    "source_files": "ImageAlertAction/Classes/**/*",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This