Reputation: 3908
i want to use button is in either way
i want to use if user select one time button then its display different color after that click on button it appear as usual after click it display that color
static int tapCount = 0;
- (IBAction)BtnClickdemo:(id)sender
{
tapCount++;
if (tapCount == 1)
[btnClick setImage:[UIImage imageNamed:@"line.png"] forState:UIControlStateNormal];
else if (tapCount == 0)
[btnClick setImage:[UIImage imageNamed:@"MinSelected.png"] forState:UIControlStateNormal];
else
{
[btnClick setImage:[UIImage imageNamed:@"MinSelected.png"] forState:UIControlStateNormal];
}
}
User only select 2 tappded like Ratingbar taped ??
How can i do ??
Upvotes: 0
Views: 294
Reputation: 630
You can assign a BOOL
value to your button and check this value everytime the button is tapped:
@implementation youCustomViewController {
BOOL buttonSelectionned;
UIButton *myButton;
}
- (void)viewDidLoad
{
/* Init objects */
buttonSelectionned = NO;
[super viewDidLoad];
// Do any additional setup after loading the view.
myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100);
myButton setImage:[UIImage imageNamed:@"MinSelected.png"] forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
}
and then implement your method buttonTapped
- (void)buttonTapped:(id)sender
{
if (buttonSelectionned) {
buttonSelectionned = NO;
myButton setImage:[UIImage imageNamed:@"MinSelected.png"] forState:UIControlStateNormal];
} else {
buttonSelectionned = YES;
myButton setImage:[UIImage imageNamed:@"MinSelected2.png"] forState:UIControlStateNormal];
}
}
Upvotes: 1