2
This commit is contained in:
72
keyBoard/Class/Search/V/KBSearchSectionHeader.m
Normal file
72
keyBoard/Class/Search/V/KBSearchSectionHeader.m
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// KBSearchSectionHeader.m
|
||||
// keyBoard
|
||||
//
|
||||
|
||||
#import "KBSearchSectionHeader.h"
|
||||
|
||||
@interface KBSearchSectionHeader ()
|
||||
@property (nonatomic, strong, readwrite) UILabel *titleLabel;
|
||||
@property (nonatomic, strong, readwrite) UIButton *trashButton;
|
||||
@end
|
||||
|
||||
@implementation KBSearchSectionHeader
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame {
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self setupUI];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setupUI {
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
[self addSubview:self.titleLabel];
|
||||
[self addSubview:self.trashButton];
|
||||
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self).offset(16);
|
||||
make.centerY.equalTo(self);
|
||||
make.right.lessThanOrEqualTo(self.trashButton.mas_left).offset(-8);
|
||||
}];
|
||||
|
||||
[self.trashButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.equalTo(self);
|
||||
make.right.equalTo(self).offset(-16);
|
||||
make.width.height.mas_equalTo(24);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)tapTrash {
|
||||
if (self.onTapTrash) { self.onTapTrash(); }
|
||||
}
|
||||
|
||||
- (void)configWithTitle:(NSString *)title showTrash:(BOOL)showTrash {
|
||||
self.titleLabel.text = title;
|
||||
self.trashButton.hidden = !showTrash;
|
||||
}
|
||||
|
||||
#pragma mark - Lazy
|
||||
|
||||
- (UILabel *)titleLabel {
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [[UILabel alloc] init];
|
||||
_titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
|
||||
_titleLabel.textColor = [UIColor colorWithHex:0x1B1F1A];
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
- (UIButton *)trashButton {
|
||||
if (!_trashButton) {
|
||||
_trashButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[_trashButton setImage:[UIImage systemImageNamed:@"trash"] forState:UIControlStateNormal];
|
||||
_trashButton.tintColor = [UIColor colorWithHex:0x9A9A9A];
|
||||
[_trashButton addTarget:self action:@selector(tapTrash) forControlEvents:UIControlEventTouchUpInside];
|
||||
}
|
||||
return _trashButton;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user