// // CustomInfoView.m // mask // // Created by 翟玉磊 on 2018/11/21. // Copyright © 2018 翟玉磊. All rights reserved. // #import "CustomInfoView.h" @interface CustomInfoView () @property (nonatomic, readwrite, strong) UIButton *button; @property (nonatomic, readwrite, strong) UIView *topLine; @property (nonatomic, readwrite, strong) UIView *bottomLine; @property (nonatomic, readwrite, strong) MASConstraint *textFiledRightConstraint; @end @implementation CustomInfoView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = Color_White; [self _setupSubViews]; } return self; } /// 设置子控件 - (void)_setupSubViews { [self addSubview:self.titleLabel]; [self addSubview:self.textField]; [self addSubview:self.moreImageView]; [self addSubview:self.button]; [self addSubview:self.topLine]; [self addSubview:self.bottomLine]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(@SPACING_EDGE); make.centerY.equalTo(self); make.width.equalTo(@60.0f); }]; [self.textField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.titleLabel.mas_right).offset(SPACING_EDGE); self->_textFiledRightConstraint = make.right.equalTo(@(-(SPACING_EDGE + 8.0f + 5.0f))); make.top.equalTo(@5.0f); make.bottom.equalTo(self).offset(-5.0f); }]; [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.button mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.left.right.equalTo(self); }]; [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.equalTo(self); make.height.equalTo(@LINE_HEIGHT); }]; [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.equalTo(self); make.height.equalTo(@LINE_HEIGHT); }]; } #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; if (isShowMoreImage) { /// 显示更多 _textFiledRightConstraint.equalTo(@(-(SPACING_EDGE + 8.0f + 5.0f))); }else { _textFiledRightConstraint.equalTo(@(-SPACING_EDGE)); } } - (void)setIsShowTopLine:(BOOL)isShowTopLine { _isShowTopLine = isShowTopLine; self.topLine.hidden = !isShowTopLine; } - (void)setIsShowBottomLine:(BOOL)isShowBottomLine { _isShowBottomLine = isShowBottomLine; self.bottomLine.hidden = !isShowBottomLine; } - (void)addTarget:(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)setPlaceholder:(NSString *)placeholder { _placeholder = placeholder; self.textField.placeholder = placeholder; } - (void)setMoreImag:(UIImage *)moreImag { _moreImag = moreImag; self.moreImageView.image = moreImag; } #pragma mark - Get/Set - (UILabel *)titleLabel { if (_titleLabel == nil) { _titleLabel = [[UILabel alloc] init]; _titleLabel.font = Font(15); _titleLabel.textColor = Color_TextFont; } return _titleLabel; } - (UITextField *)textField { if (_textField == nil) { _textField = [[UITextField alloc] init]; _textField.textColor = Color_TextFont; _textField.font = Font(15); _textField.textAlignment = NSTextAlignmentRight; } return _textField; } - (UIImageView *)moreImageView { if (_moreImageView == nil) { _moreImageView = [UIImageView new]; _moreImageView.image = arrowMore(); } return _moreImageView; } - (UIButton *)button { if (_button == nil) { _button = [UIButton buttonWithType:UIButtonTypeCustom]; [_button setBackgroundColor:Color_Clear]; } 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; _topLine.hidden = YES; } return _topLine; } @end