0

I'm trying to customize my UIAlertController with a dark theme.
I'm aiming for something like this enter image description here

I'm trying different things, including the suggestion I found here https://stackoverflow.com/a/29122883/1817873, but for some reason only the first button gets colored while the cancel button keeps staying white.

Here is my code:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:deleteAction];
[alert addAction:cancelAction];

UIView *firstView = alert.view.subviews.firstObject;
UIView *nextView = firstView.subviews.firstObject;
nextView.backgroundColor = [UIColor blackColor];

Any ideas?

Community
  • 1
  • 1
halfblood17
  • 657
  • 1
  • 6
  • 21

2 Answers2

4

Any ideas?

Yes. Give up. An alert controller is very limited, and you should stick to what it does. But it is just a presented view controller, and nothing stops you from making your own presented view controller that looks and acts just like an alert, and since it is your view controller, it's your view and you can do whatever you like.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • You are right. I ended up doing my custom UIView and simulate the same behaviour. Thank you – halfblood17 Mar 18 '16 at 17:42
  • Excellent! You might want to post your custom action sheet code on github; it might be useful to others. I have custom alert code: https://github.com/mattneub/custom-alert-view-iOS7 But my code is for an alert, not an action sheet. – matt Mar 18 '16 at 17:44
1

If you're still struggling with this, I have a library that may be of help. It lets you create custom action sheets. It has a bunch of built-in types and can be extended and restyled as well.

Daniel Saidi
  • 6,079
  • 4
  • 27
  • 29