user2928972
user2928972

Reputation: 21

UIButtonTypeSystem setBackgroundImage for UIControlStateHighlighted

In all my application i have UIButton with UIButtonTypeSystem. For ios7 I want to set buttons appearance programatically. for normal state i need white background with blue border color normal state button

for highlighted state i need grey background with blue border color highlighted state button

(and for disabled state i need white background with grey border)

I created image for each state (containing background and border color)and I set them using the UIButton's method setBackgroungImage:forState:. but when the button is in highlight state i get this button style actual highlighted state button

the only way to overcome this behavior that i found is to change all the application buttons type from UIButtonTypeSystem to UIButtonTypeCustom. meaning passing on all the application xib's

is there another way of doing so without changing all application buttons type

thanks roi

Upvotes: 2

Views: 1118

Answers (1)

Inga Codreanu
Inga Codreanu

Reputation: 21

Hello you can set you're button programatically like that:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[buuton setBackgroundColor:[UIColor colorWithRed:(255/255.0) green:(180/255.0) blue:(200/255.0) alpha:1]];
[view addSubview:button];

Upvotes: 1

Related Questions