【问题标题】:Change backgroundcolor for UIButton IPhone更改 UIButton iPhone 的背景颜色
【发布时间】:2010-07-20 07:07:32
【问题描述】:

我有问题。我使用按钮作为BarButtonItem。到目前为止它工作得很好,但我的背景色只有在我点击我的按钮时才有效。我怎样才能让它每次都设置我的背景色?

 UIButton *redEmergencyButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
 redEmergencyButton.frame = CGRectMake(100, 100, 100, 50);

 redEmergencyButton.backgroundColor = [UIColor colorWithRed:0.8 
                                                      green:0.898039215686274509803
                                                       blue:1.0 
                                                      alpha:1.0];    
 [redEmergencyButton setTitle:@"Emergency" 
                     forState:UIControlStateNormal];

 [redEmergencyButton addTarget:self 
                        action:@selector(doEmergency)
              forControlEvents:UIControlEventTouchUpInside];

 UIBarButtonItem *rButton = [[UIBarButtonItem alloc] 
          initWithCustomView:redEmergencyButton];

【问题讨论】:

  • 比 1 蓝 5 倍! :)
  • 那是一种非常特殊的绿色阴影......
  • @Jasarien:那是229/255

标签: ios iphone objective-c uibutton uibarbuttonitem


【解决方案1】:

您可以将这行代码用于您的导航栏

[self.navigationcontroller.navigationbar setTintColor:[UIColor bluecolor]];

按钮使用

那里有导航按钮。

【讨论】:

  • 如果我的回答对您有帮助,请提供给其他人并勾选此答案,抱歉我的信您可以自行更正。谢谢
【解决方案2】:

尝试使用此按钮:

UIBarButtonItem* emergencyButton = [[UIBarButtonItem alloc]initWithTitle:@"Emergency" style:UIBarButtonItemStyleBordered target:self action:@selector(doEmergency)];
[emergencyButton setTintColor: [UIColor colorWithRed:0.8 
                                                  green:0.898039215686274509803
                                                   blue:1.0 
                                                  alpha:1.0];

【讨论】:

    【解决方案3】:

    UIButtonTypeRoundedRect 在 iOS7 中已弃用,请使用 UIButtonTypeCustom 代替您的自定义 bgColor。

    UIButton *redEmergencyButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
     redEmergencyButton.frame = CGRectMake(100, 100, 100, 50);
    
     redEmergencyButton.backgroundColor = [UIColor colorWithRed:0.8 
                                                          green:0.898039215686274509803
                                                           blue:1.0 
                                                          alpha:1.0];    
     [redEmergencyButton setTitle:@"Emergency" 
                         forState:UIControlStateNormal];
    
     [redEmergencyButton addTarget:self 
                            action:@selector(doEmergency)
                  forControlEvents:UIControlEventTouchUpInside];
    
     UIBarButtonItem *rButton = [[UIBarButtonItem alloc] 
              initWithCustomView:redEmergencyButton];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-29
      • 2020-02-22
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多