Is there any way to have more than 1 red "destructive button" in an iPhone app's UIActionSheet?
I need to have different clear options, in the same action sheet, one where it deletes everything and one where it deletes less, so both need to be red.
Is there any way to have more than 1 red "destructive button" in an iPhone app's UIActionSheet?
I need to have different clear options, in the same action sheet, one where it deletes everything and one where it deletes less, so both need to be red.
I just created a simple customizable replacement for UIActionSheet for iPhone to use in a similar case. It does not use the standard appearance, but this can be changed. Probably it is of any use to you.
https://github.com/4marcus/WMActionSheet
The poster of this question seemed to manage what you want...if i understand you correctly.
Is using subviews in Alert undocumented
EDIT:
I swear I searched for UIActionSheet the first time. Really. http://www.nearinfinity.com/blogs/andrew_homeyer/display_a_custom_uiview_like_a.html
There's no supported way of doing this on the standard UIActionSheet. You could build your own "action sheet" replacement using gradient buttons like the ones here:
http://iphonedevelopment.blogspot.com/2010/05/gradient-buttons-yet-again.html
I would expect someone to have created a more customizable lookalike action sheet replacement, but I don't know of one off the top of my head.
I tried this before I saw griotspeak updated answer:
SEL getTitle = NSSelectorFromString(@"title");
SEL getBackground = NSSelectorFromString(@"background");
SEL setBackground = NSSelectorFromString(@"setBackgroundImage:");
SEL setTitleColor = NSSelectorFromString(@"setTitleColor:");
UIImage *redImage;
UIColor *titleColor;
UIColor *shadowColor;
for (NSObject *object in [action subviews]) {
if ([[NSString stringWithFormat:@"%@", [object class]] isEqualToString:@"UIThreePartButton"]) {
if ([[object performSelector:getTitle] isEqualToString:@"Clear all"]) {
redImage = [object performSelector:getBackground];
titleColor = [object performSelector:@selector(titleColor)];
shadowColor = [object performSelector:@selector(shadowColorForState:) withObject:0];
shadowOffset = [object performSelector:@selector(shadowOffset)];
}
if ([[object performSelector:getTitle] isEqualToString:@"Clear all except this month"]) {
[object performSelector:setBackground withObject:redImage];
[object performSelector:setTitleColor withObject:titleColor];
[object performSelector:@selector(setShadowColor:) withObject:shadowColor];
//[object performSelector:@selector(setShadowOffset:) withObject:CGSizeMake(-2.5,0)];
}
}
}
(I use NSSelectorFromString rather than a @selector() because it means it's not really using undocumented things, kind of, if you get what I mean)
It's not entirely documented but I don't think I've used undocumented methods. Basically what it does is take the red background from the destructive background and apply it to the other button named "Cancel".
So that should Apple change the color of the destructive button, so will the non-destructive-destructive change as well without needing an update. Although it doesn't use particularly Apple-safe methods.
I'm having a little bit of trouble with the commented-out line above, if you can help please answer here: performSelector:withObject:, but not with an object