keeping a UIButton pressed(state selected/highlighted),until another button is pressed?

前端 未结 3 1463
庸人自扰
庸人自扰 2021-02-09 19:26

I have 3 buttons at the bottom of my view controller, btn1 btn2 btn3, I\'m using them instead of the tab bar as it is not possible to entirely customize a tab bar as per my requ

3条回答
  •  不要未来只要你来
    2021-02-09 19:32

    Here's what I did:

    1. Link all 3 buttons to the following action method
    2. Create array of all 3 buttons
    3. Set the button that invoked the method to selected
    4. Set the other 2 buttons to not selected

      - (IBAction)buttonPressed:(id)sender
      {
          NSArray* buttons = [NSArray arrayWithObjects:btn1, btn2, btn3, nil];
          for (UIButton* button in buttons) {
              if (button == sender) {
                  button.selected = YES;
              }
              else {
                  button.selected = NO;
              }
          }
      }
      

    Hope this helps.

    Cheers!

提交回复
热议问题