我自定义View扩展UIView
@interface AttachmentView : UIView
@property (nonatomic, getter=isHighlighted) BOOL highlighted;
@property (weak, nonatomic) IBOutlet UIImageView *imageFileType;
@property (weak, nonatomic) IBOutlet UILabel *lbName;
@property (weak, nonatomic) IBOutlet UILabel *lbSize;
- (void)initComponent;
@end
我覆盖方法
- (void)setHighlighted:(BOOL)highlighted {
if(highlighted) {
} else {
}
}
但是当我触摸视图时,方法setHighlighted
没有调用,如何修复它?
答案 0 :(得分:1)
UIView不喜欢突出显示状态的“UILabel和UIImageView”。
您应该在- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.highlighted = !self.highlighted ;
}
或者向视图中添加UITapGestureRecognizer
或UILongPressGestureRecognizer
(如果要检测长按手势)。