4

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!

pmk
  • 1,897
  • 2
  • 21
  • 34
  • UIAlertView background seems to be an image. http://stackoverflow.com/questions/883208/changing-the-background-color-of-a-uialertview – Larme Jan 24 '13 at 18:40
  • Please refer the post : http://stackoverflow.com/questions/1181272/iphone-development-how-to-create-colored-or-translucent-background-for-uiactions That will be useful for you. – Saurabh Shukla Jan 24 '13 at 18:55
  • Thanks for your replies! Unfortunately I am not able to remove the boarder, no matter if I use an Image or set the backGroundColor of the Layer – pmk Jan 24 '13 at 21:09
  • Have you tried something like this? http://stackoverflow.com/questions/1301909/uiactionsheet-tinting – ryanwils Mar 04 '13 at 20:43
  • Also, I've had issues with UIActionSheet on iPad before, I believe the best way about it is to use a UIPopoverController. – ryanwils Mar 04 '13 at 20:46

2 Answers2

1

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.

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • This is exactly what I needed. It does not yet look nice, but the backgroundView gets removed, and that's what my question was about. I just need to add my own background with my own colors and stuff. I will post some code when it's done. Thank you very much, this was really helpful! – pmk Mar 11 '13 at 18:04
0

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
            }
        }
    }
Maximilian Litteral
  • 3,059
  • 2
  • 31
  • 41
  • Thanks for your answer. Unfortunately your code does exactly the same as mine, it works for iPhone, but not on the iPad. The uncolored border is still there :( – pmk Mar 10 '13 at 21:53
  • In this code, use NSLog to log the subviews, and then try and find an image. Should be 2 of them i guess, in the top i themed the first one, but on ipad there must be 2, so you need to hide it or have a image for it it – Maximilian Litteral Mar 10 '13 at 23:58