我正在使用UIButton上的reversesTitleShadowWhenHighlighted
属性来反转标题的文本阴影(并且效果很好),但我真的希望按钮的选定状态(UIControlStateSelected
)具有相同的功能。
欢迎任何相关问题的答案:
UIButton
执行此操作? 答案 0 :(得分:2)
我遇到了同样的问题,所以我想你的前两个问题是不对的。以下是我将其子类化的方法:
@interface MyButton : UIButton
@property (nonatomic) BOOL reversesTitleShadowWhenSelected;
@end
@implementation MyButton
@synthesize reversesTitleShadowWhenSelected;
- (void)setSelected:(BOOL)selected
{
if (self.reversesTitleShadowWhenSelected)
{
if ((selected && !self.isSelected) ||
(!selected && self.isSelected))
{
CGSize offset = self.titleLabel.shadowOffset;
offset.width *= -1;
offset.height *= -1;
self.titleLabel.shadowOffset = offset;
}
}
[super setSelected:selected];
}
@end