所以我将 UIButton 子类化了,我添加到它的唯一方法是 setTitle(我使用的是图标字体,所以我为那些通过图标表示的按钮创建了一个 Icon_UIButton)。
我有这个代码:
Icon_UIButton* button = [[Icon_UIButton alloc] init];
[button setTitle:@"R"]; //R is a specific icon in my icon font
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
这看起来很有效,但是在我将按钮设置为选中后,使用:
[button setSelected:YES];
每当我点击并按住该按钮时,它就会再次变黑。
这就像一个选定的 Icon_UIButton 在同时被选中时忽略了它的 titleColor 以突出显示状态。
有人经历过吗?