5

有没有办法在 iPhone 应用程序的 UIActionSheet 中有超过 1 个红色“破坏性按钮”?

我需要有不同的清除选项,在同一个操作表中,一个删除所有内容,一个删除较少,所以两者都需要是红色的。

4

4 回答 4

2

我刚刚为 iPhone 的 UIActionSheet 创建了一个简单的可定制替代品,以便在类似情况下使用。它不使用标准外观,但这可以更改。可能它对你有用。

https://github.com/4marcus/WMActionSheet

于 2010-12-16T10:57:23.180 回答
2

这个问题的海报似乎可以管理你想要的......如果我理解正确的话。

在未记录的警报中使用子视图

编辑:

我发誓我第一次搜索 UIActionSheet。真的。 http://www.nearinfinity.com/blogs/andrew_homeyer/display_a_custom_uiview_like_a.html

于 2010-12-05T18:44:45.287 回答
1

在标准 UIActionSheet 上没有支持的方法。您可以使用如下所示的渐变按钮构建自己的“操作表”替换:

http://iphonedevelopment.blogspot.com/2010/05/gradient-buttons-yet-again.html

我希望有人创建了一个更可定制的外观相似的操作表替换,但我不知道有一个在我的脑海中。

于 2010-12-05T18:58:13.107 回答
0

在看到 griotspeak 更新的答案之前,我尝试了这个:

SEL getTitle = NSSelectorFromString(@"title");
SEL getBackground = NSSelectorFromString(@"background");
SEL setBackground = NSSelectorFromString(@"setBackgroundImage:");
SEL setTitleColor = NSSelectorFromString(@"setTitleColor:");
UIImage *redImage;
UIColor *titleColor;
UIColor *shadowColor;
for (NSObject *object in [action subviews]) {
    if ([[NSString stringWithFormat:@"%@", [object class]] isEqualToString:@"UIThreePartButton"]) {
        if ([[object performSelector:getTitle] isEqualToString:@"Clear all"]) {
            redImage = [object performSelector:getBackground];
            titleColor = [object performSelector:@selector(titleColor)];
            shadowColor = [object performSelector:@selector(shadowColorForState:) withObject:0];
            shadowOffset = [object performSelector:@selector(shadowOffset)];
        }
        if ([[object performSelector:getTitle] isEqualToString:@"Clear all except this month"]) {
            [object performSelector:setBackground withObject:redImage];
            [object performSelector:setTitleColor withObject:titleColor];
            [object performSelector:@selector(setShadowColor:) withObject:shadowColor];
            //[object performSelector:@selector(setShadowOffset:) withObject:CGSizeMake(-2.5,0)];
        }
    }

}

(我使用 NSSelectorFromString 而不是 @selector() 因为这意味着它并没有真正使用未记录的东西,有点,如果你明白我的意思的话)

它没有完全记录在案,但我认为我没有使用过未记录的方法。基本上它所做的是从破坏性背景中获取红色背景并将其应用于另一个名为“取消”的按钮。

因此,如果 Apple 更改破坏性按钮的颜色,那么非破坏性破坏性更改也将如此,而无需更新。尽管它没有使用特别适合 Apple 的方法。

我对上面注释掉的行有点麻烦,如果你能帮忙,请在这里回答:performSelector:withObject:,但不是对象

于 2010-12-05T21:12:58.137 回答