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];
And that's how it's done:
let image = UIImage(named: "myImage") var action = UIAlertAction(title: "title", style: .default, handler: nil) action.setValue(image, forKey: "image") alert.addAction(action)
the image property is not exposed, so there's no guarantee of this working in future releases, but works fine as of now
UIAlertController * view= [UIAlertController alertControllerWithTitle:@"Staus ! " message:@"Select your current status" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction* online = [UIAlertAction actionWithTitle:@"Online" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { //Do some thing here [view dismissViewControllerAnimated:YES completion:nil]; }]; UIAlertAction* offline = [UIAlertAction actionWithTitle:@"Offline" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [view dismissViewControllerAnimated:YES completion:nil]; }]; UIAlertAction* doNotDistrbe = [UIAlertAction actionWithTitle:@"Do not disturb" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { [view dismissViewControllerAnimated:YES completion:nil]; }]; UIAlertAction* away = [UIAlertAction actionWithTitle:@"Do not disturb" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) { [view dismissViewControllerAnimated:YES completion:nil]; }]; [online setValue:[[UIImage imageNamed:@"online.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"]; [offline setValue:[[UIImage imageNamed:@"offline.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"]; [doNotDistrbe setValue:[[UIImage imageNamed:@"DND.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"]; [away setValue:[[UIImage imageNamed:@"away.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"]; [view addAction:online]; [view addAction:away]; [view addAction:offline]; [view addAction:doNotDistrbe]; [self presentViewController:view animated:YES completion:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With