// // CustomBoxView.m // MIT_Endorsement // // Created by 翟玉磊 on 2017/9/21. // Copyright © 2017年 翟玉磊. All rights reserved. // #import "CustomBoxView.h" @interface CustomBoxView () @property (nonatomic, strong) UIButton *button; @property (nonatomic, strong) UIView *topLine; @property (nonatomic, strong) UIView *bottomLine; @end @implementation CustomBoxView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self initValue]; [self buildView]; } return self; } - (instancetype)init { if (self = [super init]) { [self initValue]; [self buildView]; } return self; } - (void)initValue { self.backgroundColor = [UIColor whiteColor]; self.isClick = NO; self.isShowMoreImage = NO; self.isShowBottomLine = YES; self.button.hidden = YES; self.moreImageView.hidden = YES; self.bottomLine.hidden = NO; self.isShowTopLine = NO; self.topLine.hidden = YES; //顶部分割线默认隐藏 } - (void)buildView { [self addSubview:self.topLine]; [self addSubview:self.titleLabel]; [self addSubview:self.moreImageView]; [self addSubview:self.bottomLine]; [self addSubview:self.button]; [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.equalTo(self); make.height.equalTo(@0.5); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self).offset(SPACING_EDGE); make.centerY.equalTo(self); }]; [self.moreImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self).offset(-SPACING_EDGE); make.centerY.equalTo(self); make.width.equalTo(@8.0f); make.height.equalTo(@13.0f); }]; [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.equalTo(self); make.height.equalTo(@0.5); }]; [self.button mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.top.equalTo(self); }]; } #pragma mark - Public - (void)setTitle:(NSString *)title { _title = title; self.titleLabel.text = title; } - (void)setTitleColor:(UIColor *)titleColor { _titleColor = titleColor; self.titleLabel.textColor = titleColor; } - (void)setIsClick:(BOOL)isClick { _isClick = isClick; self.button.hidden = !isClick; } - (void)setIsShowMoreImage:(BOOL)isShowMoreImage { _isShowMoreImage = isShowMoreImage; self.moreImageView.hidden = !isShowMoreImage; } - (void)setIsShowTopLine:(BOOL)isShowTopLine { _isShowTopLine = isShowTopLine; self.topLine.hidden = !isShowTopLine; } - (void)setIsShowBottomLine:(BOOL)isShowBottomLine { _isShowBottomLine = isShowBottomLine; self.bottomLine.hidden = !isShowBottomLine; } - (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents { self.button.hidden = NO; [self.button addTarget:target action:action forControlEvents:controlEvents]; } - (void)setFont:(UIFont *)font { _font = font; self.titleLabel.font = font; } - (void)setMoreImag:(UIImage *)moreImag { _moreImag = moreImag; self.moreImageView.image = moreImag; } #pragma mark - Getter - (UILabel *)titleLabel { if (_titleLabel == nil) { _titleLabel = [UILabel new]; _titleLabel.font = Font(15); _titleLabel.textColor = Color_TextFont; } return _titleLabel; } - (UIImageView *)moreImageView { if (_moreImageView == nil) { _moreImageView = [UIImageView new]; _moreImageView.image = arrowMore(); } return _moreImageView; } - (UIButton *)button { if (_button == nil) { _button = [UIButton buttonWithType:UIButtonTypeCustom]; [_button setBackgroundColor:[UIColor clearColor]]; } return _button; } - (UIView *)bottomLine { if (_bottomLine == nil) { _bottomLine = [UIView new]; _bottomLine.backgroundColor = Color_line; } return _bottomLine; } - (UIView *)topLine { if (_topLine == nil) { _topLine = [UIView new]; _topLine.backgroundColor = Color_line; } return _topLine; } @end