UIActionSheet破坏性按钮缺少背景

时间:2013-11-08 19:21:18

标签: ios cocoa-touch ios7 uiactionsheet

我有UIActionSheet我有条件地添加按钮。如果有很多按钮(对于纵向视图更是如此),破坏性按钮会从操作表中分离(如预期的那样)以允许项目滚动。不对的是,它没有背景。

iOS7 screenshot

UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:nil 
                                                  delegate:self
                                         cancelButtonTitle: nil
                                    destructiveButtonTitle:@"Changed my mind"
                                         otherButtonTitles:MAILBUTTON, BOOKMARKSBUTTON, CLEARCOOKIESBUTTON, nil];


if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    [sheet addButtonWithTitle:CAMERABUTTON];
}

sheet.tag = ACTION_SHEET;

if ([UIPrintInteractionController isPrintingAvailable])
{
    [sheet addButtonWithTitle:PRINTBUTTON];
}   

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if ([prefs boolForKey:BUMP_ENABLED_KEY] == YES)
{
    [sheet addButtonWithTitle:BUMPRECEIVEBUTTON];
    if ([prefs boolForKey:BUMP_ALLOW_SENDING_KEY] == YES)
        [sheet addButtonWithTitle:BUMPSENDBUTTON];
}

[sheet addButtonWithTitle: @""];
[sheet setCancelButtonIndex: sheet.numberOfButtons - 1];

[sheet showInView:self.view];

在纵向模式下看起来很好,破坏性按钮有背景。如果我添加了更多按钮,它具有与上面相同的行为。

1 个答案:

答案 0 :(得分:0)

找到一个解决方案,有点hacky。首先,我检查它是否有景观,并且有超过5个按钮。如果有6个或更多,那么当它变为滚动操作表时,就会出现问题。如果一切正确,我将标题设置为空字符串,并带有空格

[sheet setTitle: @" "];

这为按钮提供了白色背景,但是如果您不想要标题,它会给我们留下一个空白空间。

要解决此问题,请在willPresentActionSheet中向下滑动背景

        if (actionSheet.title)
        {
            if ([actionSheet.title.trim isEqualToString: @""])
            {
                CGRect backdropFrame = [[[actionSheet subviews] objectAtIndex: 0] frame];
                backdropFrame.origin.y += 45;
                backdropFrame.size.height -= 55;
                [[[actionSheet subviews] objectAtIndex: 0] setFrame: backdropFrame];
            }
        }