123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- //
- // 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
|