iPhone UIButton with UISwitch functionality

前端 未结 4 1643
轮回少年
轮回少年 2020-12-02 09:01

Is there either a way to implement UISwitch with custom graphics for the switch-states? Or as an alternative the other way round, an UIButton with UISwitch functionality?

4条回答
  •  忘掉有多难
    2020-12-02 09:42

    set the image to show on selected state:

    [button setImage:[UIImage imageNamed:@"btn_graphics"] forState:UIControlStateSelected];
    

    and then on touch up inside selector, set:

    button.selected = YES;
    

    if you want this to cancel another button's selection, set:

    otherButton.selected = NO;
    

提交回复
热议问题