开发者

Drawing a custom button

开发者 https://www.devze.com 2023-01-28 10:54 出处:网络
I am drawing a custom button: UIButton *myButton = [UIButton buttonWithType:UIButt开发者_如何学JAVAonTypeCustom];

I am drawing a custom button:

UIButton *myButton = [UIButton buttonWithType:UIButt开发者_如何学JAVAonTypeCustom];
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?


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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消