多个红色/破坏性按钮 UIActionSheet

发布于 2024-10-06 11:08:00 字数 119 浏览 6 评论 0原文

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

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

Is there any way to have more than 1 red "destructive button" in an iPhone app's UIActionSheet?

I need to have different clear options, in the same action sheet, one where it deletes everything and one where it deletes less, so both need to be red.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

醉生梦死 2024-10-13 11:08:00

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

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

I just created a simple customizable replacement for UIActionSheet for iPhone to use in a similar case. It does not use the standard appearance, but this can be changed. Probably it is of any use to you.

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

菊凝晚露 2024-10-13 11:08:00

这个问题的发布者似乎可以管理你想要的东西......如果我理解正确的话。

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

编辑:

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

The poster of this question seemed to manage what you want...if i understand you correctly.

Is using subviews in Alert undocumented

EDIT:

I swear I searched for UIActionSheet the first time. Really.
http://www.nearinfinity.com/blogs/andrew_homeyer/display_a_custom_uiview_like_a.html

雨的味道风的声音 2024-10-13 11:08:00

标准 UIActionSheet 上不支持执行此操作的方法。您可以使用渐变按钮构建自己的“操作表”替代品,如下所示:

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

我希望有人创建一个更可定制的相似操作表替代品,但我不这样做我立刻就知道其中一个。

There's no supported way of doing this on the standard UIActionSheet. You could build your own "action sheet" replacement using gradient buttons like the ones here:

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

I would expect someone to have created a more customizable lookalike action sheet replacement, but I don't know of one off the top of my head.

微凉 2024-10-13 11:08:00

在看到 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() 因为这意味着它并没有真正使用未记录的东西,如果你明白我的意思的话)

它没有完全记录,但我没有我想我使用了未记录的方法。
基本上它的作用是从破坏性背景中取出红色背景并将其应用到另一个名为“取消”的按钮。

因此,如果苹果改变破坏性按钮的颜色,非破坏性按钮的颜色也会改变,而无需更新。尽管它没有使用特别对苹果安全的方法。

我在上面的注释行上遇到了一些麻烦,如果您可以帮忙,请在这里回答:performSelector:withObject:,但不使用对象

I tried this before I saw griotspeak updated answer:

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

}

(I use NSSelectorFromString rather than a @selector() because it means it's not really using undocumented things, kind of, if you get what I mean)

It's not entirely documented but I don't think I've used undocumented methods.
Basically what it does is take the red background from the destructive background and apply it to the other button named "Cancel".

So that should Apple change the color of the destructive button, so will the non-destructive-destructive change as well without needing an update. Although it doesn't use particularly Apple-safe methods.

I'm having a little bit of trouble with the commented-out line above, if you can help please answer here: performSelector:withObject:, but not with an object

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文