I have seen a couple screen shots of a UIAlertControllers with an image on the left of the row but I do not seen it in the documentation. An example visual is Here is the code that I have for my controller right now:
UIAlertController * view = [UIAlertController
alertControllerWithTitle:@"My Title"
message:@"Select you Choice"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
}];
[view addAction:ok];
[self presentViewController:view animated:YES completion:nil];
You could add image above title label by subclassing
UIAlertController
and adding\n
to title string to make space forUIImageView
. You'd have to compute layout based on font size. For images inUIAlertAction
usingKVC
like soself.setValue(image, forKey: "image")
. I would recommend extension that checks forresponds(to:)
. Here is sample implementation.swift 3 extension , property and convenience init.
thanks to Shahar Stern for the inspiration
And that's how it's done:
the image property is not exposed, so there's no guarantee of this working in future releases, but works fine as of now
Try something like this:
Tested this and it works for iOS 7.0
For swift
Note: IMP Line withRenderingMode(.alwaysOriginal)
Swift Version: