【问题标题】:Change the color of a button on a standard pop-up action更改标准弹出操作上的按钮颜色
【发布时间】:2010-11-28 03:34:11
【问题描述】:

我在我的 iphone 应用程序中使用标准弹出操作(屏幕底部的弹出)。这有 2 个按钮“确定”和“取消”。似乎标准的配色方案是将顶部按钮设置为红色。我想改变这个,所以顶部的按钮是绿色的。我一直在谷歌搜索,找不到解决方案。任何想法都会很棒。谢谢

【问题讨论】:

    标签: iphone button colors


    【解决方案1】:

    您可以浏览 ActionSheet(我假设您使用 UIActionSheet 类)子视图 - 就像这样:

    NSArray* subViews = [aSheet subviews];
    for (UIView* sView in subViews)
    {
        ...
    }
    

    并根据需要更改那里的子视图属性。

    您也可以创建不带任何按钮的 UIActionSheet:

    UIActionSheet* aSheet = [[UIActionSheet alloc] initWithTitle:@"\n\n\n" delegate:self cancelButtonTitle:nil  destructiveButtonTitle:nil otherButtonTitles:nil];
    

    然后创建您自己的自定义按钮并将它们添加到 ActionSheet 视图中。 (在标题中添加更多 \n 以放大工作表高度)

    【讨论】:

      【解决方案2】:

      我假设您指的是 UIActionSheet。在 UIActionSheet 中,您可以定义取消操作并具有黑色背景的按钮、标记破坏性操作并具有红色背景的按钮以及具有白色背景的所有其他按钮。在 UIActionSheet 的初始化中,可以使用– initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles: 指定哪个选项对应哪个类的动作。

      iPhone Human Interface Guidelines 中解释了 UIActionSheet 的设计,包括为什么您应该只为按钮使用这些颜色。在这方面我会遵循 Apple 的建议,因为它们会使您的应用程序更易于使用。

      【讨论】:

        【解决方案3】:
        UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@""
                                  delegate:self 
                                  cancelButtonTitle:@"Cancel" 
                                  destructiveButtonTitle:nil,@"Mail",@"Facebook",@"Twitter",nil
                                  otherButtonTitles:nil];
        NSArray *buttons = [action subviews];
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2022-01-01
          • 2015-09-07
          • 1970-01-01
          • 1970-01-01
          • 2012-07-10
          • 2018-12-11
          • 1970-01-01
          相关资源
          最近更新 更多