这里的许多问题都询问如何让按钮保持选中状态,我问为什么我的按钮保持选中状态,以及如何删除它?我创建了一个自定义UIView类,程序上添加了一个UIButton,如下所示。
// Toolbar
UIView *toolbar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 33.0f)];
toolbar.backgroundColor = [UIColor colorWithRed: 238.0/255.0f green: 238.0/255.0f blue: 238.0/255.0f alpha:1];
_button = [[UIButton alloc] initWithFrame:CGRectMake(263.0f, 3.0f, 37.0f, 30.0f)];
// Create button
[_button setTitle:@"Done" forState:UIControlStateNormal];
_button.titleLabel.font = [UIFont systemFontOfSize:15.0f];
_button.titleLabel.textColor = [UIColor colorWithRed:92.0/255.0f green:92.0/255.0f blue:92.0/255.0f alpha:1];
[_button addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
[toolbar addSubview:_button]
// Add toolbar to UIView class
[self addSubview:toolbar];
在工具栏上单击按钮时,它会从黑色变为白色并保持白色。这是为什么?