Change backgroundcolor for UIButton IPhone
        Posted  
        
            by 
                lightwave
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by lightwave
        
        
        
        Published on 2010-07-20T07:07:32Z
        Indexed on 
            2012/11/08
            5:02 UTC
        
        
        Read the original article
        Hit count: 223
        
I have a problem. I use a Button as a BarButtonItem. It works fine so far, but my backgroundcolor works only if I click on my button. How can I make it so that my backgroundcolor will be set every time ?
 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];
        © Stack Overflow or respective owner