Reputation: 3475
I changed a button color using the following code:
[self.testButton setBackgroundColor:[UIColor redColor]];
but I got a weird button:
why the button background color didn't change?
Upvotes: 2
Views: 8225
Reputation: 437
Change the button type to Custom in Attributes inspector in your .xib then check your code
[self.testButton setBackgroundColor:[UIColor redColor]];
Upvotes: 2
Reputation: 23278
You can import #import <QuartzCore/QuartzCore.h>
and try this,
self.testButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.testButton.backgroundColor = [UIColor redColor];
self.testButton.layer.borderColor = [UIColor blackColor].CGColor;
self.testButton.layer.borderWidth = 0.5f;
self.testButton.layer.cornerRadius = 10.0f;
Or else you can use some custom image as the background image for this button.
Upvotes: 10