Question

I'm struggeling with an issuse for quite a while now. Since I don't really find a solution, I hope somebody here will be able to help me.

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

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

I am able to change most of the alert's color. This is how 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!

Was it helpful?

Solution

You can't redraw the border in a different color, so just remove 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 won't work in *will*PresentActionSheet since actionSheet doesn't have a superview set at that point.

OTHER TIPS

This works on iPhone to theme it, It will probably work on iPad also.

    - (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
            }
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top