【问题标题】:UIActionSheet destructive button missing backgroundUIActionSheet 破坏性按钮缺少背景
【发布时间】:2013-11-08 19:21:18
【问题描述】:

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

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];

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

【问题讨论】:

  • 有同样的问题。你有没有找到一个不那么 hacky 的解决方案?谢谢。
  • @anas 不,我坚持使用这个解决方案。我们已经在多种设备和不同的操作系统版本上进行了多次测试,但没有遇到问题。下一个最好的事情是苹果解决这个错误,IMO

标签: ios cocoa-touch ios7 uiactionsheet


【解决方案1】:

找到了一个解决方案,它有点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];
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2016-11-16
    • 2022-08-16
    • 1970-01-01
    • 1970-01-01
    • 2020-04-18
    相关资源
    最近更新 更多