tags:

views:

52

answers:

4

i want to change the button color when it is clicked .i used [button setbackgroundcolor:[uicolor redcolor]]; but this shows red color only on the four corners of button not on the whole button and also when i use "for state:uicontrolstate...." then the application hangs . is their any way to show some color on button when clicked?

[click1 setBackgroundColor:[UIColor redColor]forState:UIControlStateHighlighted];

good answers will be rewarded

+1  A: 

you have take a red color image for your button and then you can set it when user clicks

[yourButtonName setBackgroundImage:[UIImage imageNamed:@"yourRedButton.png"] forState:UIControlStateHighlighted];
Gyani
but i dont want to use an image only color when button is clicked
pankaj kainthla
there is no method like what you trying
Gyani
+1  A: 

Make the button type as custom.

Eg

button = [UIButton buttonWithType:UIButtonTypeCustom];

All the best.

Warrior
but custom removes the round cornered button .i think nobody will want this i think i have to use image instead which i never wabted to use
pankaj kainthla
Even if you use image, you should make button type as custom for good look.Feel the difference.Try it.
Warrior
+1  A: 

@pankaj Gyani says correct

arunkumar.p
+2  A: 

@pankaj Gyani says correct

UIButton *button = [[UIButton buttonWithType:UIButtonTypeCustom] initWithFrame:CGRectMake(0, 0, 24, 24)]; [button addTarget:self action:@selector(prevButtonClick:) forControlEvents:UIControlEventTouchUpInside]; [button setBackgroundImage:[UIImage imageNamed:@"IntroArrowLeft.png"] forState:UIControlStateNormal]; [self addSubview:button];

arunkumar.p
You can edit your own post,instead of answering multiple times.
Warrior
yeah warrior is right
pankaj kainthla