Abhinav
Abhinav

Reputation: 38162

Drawing a custom button

I am drawing a custom button:

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.frame = CGRectMake(10,10,44,70);
[myButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[myButton setTitle:@"Order" forState:UIControlStateNormal];                   

When I am tapping on the button the back ground color is not changing. Do I need to use different images for normal and selected state? What is the trick here?

Upvotes: 1

Views: 340

Answers (2)

vincent
vincent

Reputation: 441

Yes. because you're using a custom button, you need to describe every single state manually or they will look like the normal state.

Upvotes: 0

Jacob Relkin
Jacob Relkin

Reputation: 163308

Yes, you need to use different images for different states:

[myButton setBackgroundImage:someUIImageRef forState:UIControlStateNormal];
[myButton setBackgroundImage:someOtherUIImageRef forState:UIControlStateHighlighted];

Upvotes: 2

Related Questions