0

enter image description here

I want to achieve the following picture's button state. When the "starts.." area is touched, the area is highlighted and a datepicker pops up. My approach is creating a full-width button and place two labels Starts, Today 12:00AM on top of it. When the user touches the button I respond to the action by pulling up a datepicker. Here are my questions.

  1. Is this approach conventional?
  2. How do I make a button go into a "selected" state? I tried the following to change the background image:

    UIImage *buttonImage = [[UIImage imageNamed:@"btn_carrot.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)]; UIImage *buttonImageHighlight = [[UIImage imageNamed:@"btn_light_carrot.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)]; [self.startDateButton setBackgroundImage:buttonImage forState:UIControlStateNormal]; [self.startDateButton setBackgroundImage:buttonImageHighlight forState:(UIControlStateHighlighted | UIControlStateSelected)];

However, the button never goes into a selected state. It changes its color briefly. Thank you!

Maximus S
  • 10,759
  • 19
  • 75
  • 154

2 Answers2

0

Try setHighlighted after the button triggers:

[self.startDateButton setHighlighted:YES];
0

You can use - tableView:didSelectRowAtIndexPath: in UITableViewDelegate to respond user's touch action, and customize your cell by - tableView:cellForRowAtIndexPath: in UITableViewDataSource.

Wei
  • 3,492
  • 4
  • 18
  • 18