iPhone toggle button implementation

前端 未结 7 1974
孤独总比滥情好
孤独总比滥情好 2021-02-04 09:05

I would like to create a toggle button in my iPhone application. However, I don\'t know exactly what would be the best approach for this.

I am considering two options.

7条回答
  •  猫巷女王i
    2021-02-04 09:17

    -(IBAction)toggle{
        if (button.selected == NO) {
            button.selected = YES;
    
        }
        else {
            button.selected = NO;
        }
    }
    

    or

    -(IBAction)toggle:(UIButton*)sender
    {
    sender.selected = !sender.selected;
    }
    

    simple dude

提交回复
热议问题