Objective c iPad上的UIActionSheet背景色

Objective c iPad上的UIActionSheet背景色,objective-c,ipad,uiactionsheet,tintcolor,Objective C,Ipad,Uiactionsheet,Tintcolor,我为一个问题苦苦挣扎了好一阵子。既然我真的没有找到解决办法,我希望这里有人能帮助我 我有一个UIActionSheet,我想有一个不同的背景色。 与 [[myAlert layer]setBackgroundColor:[UIColor redColor].CGColor] 我可以更改警报的大部分颜色。 这就是它的样子: 以下是初始化UIActionSheet的方式: UIActionSheet *styleAlert = [[UIActionSheet alloc] initWith

我为一个问题苦苦挣扎了好一阵子。既然我真的没有找到解决办法,我希望这里有人能帮助我

我有一个UIActionSheet,我想有一个不同的背景色。 与

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

我可以更改警报的大部分颜色。 这就是它的样子:

以下是初始化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];

我不知道如何设置相同颜色的边框。有什么想法吗


提前谢谢

这在iPhone上可以实现,在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
            }
        }
    }

您不能用其他颜色重新绘制边框,因此只需删除边框并添加您自己的:

- (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
    }
}

请注意,这在*will*PresentActionSheet中不起作用,因为
actionSheet
在该点没有设置
superview

UIAlertView背景似乎是图像。请参考帖子:这对你很有用。谢谢你的回复!不幸的是,无论我是使用图像还是设置图层的背景色,我都无法删除边界。您尝试过类似的方法吗?另外,我以前在iPad上遇到过UIActionSheet的问题,我认为最好的方法是使用UIPopoverController。谢谢你的回答。不幸的是,您的代码与我的代码完全相同,它适用于iPhone,但不适用于iPad。未着色的边界仍然存在:(在这段代码中,使用NSLog记录子视图,然后尝试查找一个图像。我想应该是其中的两个,在顶部我为第一个设置了主题,但在ipad上必须有两个,所以你需要隐藏它或为它设置一个图像。这正是我所需要的。它看起来还不好看,但背景视图被删除了,这就是我的问题所在。)ut。我只需要用我自己的颜色和东西添加我自己的背景。完成后我会发布一些代码。非常感谢,这真的很有帮助!
- (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
    }
}