4

我在一个问题上苦苦挣扎了很长一段时间。由于我并没有真正找到解决方案,我希望这里有人能够帮助我。

我有一个 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];

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

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

提前致谢!

4

2 回答 2

1

你不能用不同的颜色重新绘制边框,所以只需删除边框并添加你自己的:

- (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集合。

于 2013-03-11T14:33:45.390 回答
0

这适用于 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
            }
        }
    }
于 2013-03-09T22:41:55.237 回答