UIActionSheet backGroundColor on iPad

I have been struggling with issuse for quite some time. Since I really can't find a solution, I hope someone here can help me.

I have a UIActionSheet that I want to have a different background color. Via

[[myAlert layer] setBackgroundColor:[UIColor redColor].CGColor];

I can change most of the color warnings. Here's what it looks like:

This is how it looks

This is how I initialize the UIActionSheet:

  UIActionSheet *styleAlert = [[UIActionSheet alloc] initWithTitle:AMLocalizedString(@"SELECT_PICTURE_TITLE", @"Überschrift des Actionsheets") delegate:self cancelButtonTitle:AMLocalizedString(@"CANCEL_BUTTON_TITLE", @"Abbrechen butten") destructiveButtonTitle:nil otherButtonTitles:AMLocalizedString(@"TAKE_PICTURE_BUTTON_TITLE", @"Bild aufnehmen button"), AMLocalizedString(@"CAMERA_ROLL_BUTTON_TITLE", @"Aus Bibliothek auswählen"), nil]; // use the same style as the nav bar [styleAlert showInView:self.parentViewController.tabBarController.view]; //[styleAlert showInView:[self.navigationController view] ]; [styleAlert release]; 

and

 - (void)willPresentActionSheet:(UIActionSheet *)actionSheet { actionSheet.layer.backgroundColor = GLOBAL_TINT_COLOR.CGColor; } 

I could not figure out how to set the border with the same color. Any ideas?

Thanks in advance!

+4
source share
2 answers

You cannot redraw the border in a different color, so just delete the border and add your own:

 - (void)didPresentActionSheet:(UIActionSheet *)actionSheet { UIView *contentView = actionSheet.superview; UIView *popoverView = contentView.superview; UIView *chromeView; for (UIView *v in [popoverView subviews]) { if (v.subviews.count == 3) { chromeView = v; break; } } for (UIView *backgroundComponentView in [chromeView subviews]) { backgroundComponentView.hidden = YES; CGRect componentFrame = backgroundComponentView.frame; // add your view with this frame } } 

Note that this will not work in * will * PresentActionSheet, since the actionSheet does not have a superview set at this point.

+1
source

This works on the iPhone for its theme, and will probably work on the iPad.

  - (void)willPresentActionSheet:(UIActionSheet *)actionSheet { UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed@ ""]]; imageView.frame = CGRectMake(0, 0, actionSheet.frame.size.width, actionSheet.frame.size.height); [actionSheet insertSubview:imageView atIndex:0]; NSArray *subviews = [actionSheet subviews]; for (UIView *v in subviews) { if ([v isKindOfClass:[UIButton class]]) { //Theme the buttons on the action sheet UIButton *b = (UIButton *)v; } else if ([v isKindOfClass:[UILabel class]]) { UILabel *l = (UILabel *)v; //Theme the label at the top of the action sheet } } } 
0
source

All Articles