当选择 UIButton 时,这个按钮工件是什么?

cir*_*ego 4 selected uibutton uikit uicontrol ios

我正在尝试使用以下代码将 UI 按钮设为切换按钮:

- (void)tapButton:(id)sender{
    UIButton *button = sender;
    if (!button.selected){
        [self performSelector:@selector(highlight:) withObject:button afterDelay:0.0];
    }else{
        [self performSelector:@selector(removeHighlight:) withObject:button afterDelay:0.0];
    }
}

- (void)highlight:(UIButton *)button{
    button.selected = !button.selected;
    button.highlighted = YES;
}

- (void)removeHighlight:(UIButton *)button{
    button.selected = !button.selected;
    button.highlighted = NO;
}
Run Code Online (Sandbox Code Playgroud)

但是,当按钮处于选定模式时,我遇到了奇怪的现象。

未选中的:

在此输入图像描述

已选择:

在此输入图像描述

Gan*_*olo 5

只需将按钮类型设置为“自定义”而不是“系统”即可。我猜这个奇怪的错误与 iOS7 上新的 Tint 功能有关。这可能是有问题的,因为你的 title 属性是一个空字符串@""。