多个红色/破坏性按钮UIActionSheet

时间:2010-12-05 18:34:00

标签: iphone objective-c uiactionsheet

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

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

4 个答案:

答案 0 :(得分:2)

这个问题的海报似乎能够管理你想要的......如果我理解你的话。

Is using subviews in Alert undocumented

编辑:

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

答案 1 :(得分:2)

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

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

答案 2 :(得分:1)

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

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

我希望有人能够创建一个更加可自定义的相似的动作表替代品,但我不知道有哪一个在我的头顶。

答案 3 :(得分: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:, but not with an object

相关问题