CustomInfoView.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // CustomInfoView.m
  3. // mask
  4. //
  5. // Created by 翟玉磊 on 2018/11/21.
  6. // Copyright © 2018 翟玉磊. All rights reserved.
  7. //
  8. #import "CustomInfoView.h"
  9. @interface CustomInfoView ()
  10. @property (nonatomic, readwrite, strong) UIButton *button;
  11. @property (nonatomic, readwrite, strong) UIView *topLine;
  12. @property (nonatomic, readwrite, strong) UIView *bottomLine;
  13. @property (nonatomic, readwrite, strong) MASConstraint *textFiledRightConstraint;
  14. @end
  15. @implementation CustomInfoView
  16. - (instancetype)initWithFrame:(CGRect)frame {
  17. if (self = [super initWithFrame:frame]) {
  18. self.backgroundColor = Color_White;
  19. [self _setupSubViews];
  20. }
  21. return self;
  22. }
  23. /// 设置子控件
  24. - (void)_setupSubViews {
  25. [self addSubview:self.titleLabel];
  26. [self addSubview:self.textField];
  27. [self addSubview:self.moreImageView];
  28. [self addSubview:self.button];
  29. [self addSubview:self.topLine];
  30. [self addSubview:self.bottomLine];
  31. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.left.equalTo(@SPACING_EDGE);
  33. make.centerY.equalTo(self);
  34. make.width.equalTo(@60.0f);
  35. }];
  36. [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.equalTo(self.titleLabel.mas_right).offset(SPACING_EDGE);
  38. self->_textFiledRightConstraint = make.right.equalTo(@(-(SPACING_EDGE + 8.0f + 5.0f)));
  39. make.top.equalTo(@5.0f);
  40. make.bottom.equalTo(self).offset(-5.0f);
  41. }];
  42. [self.moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.right.equalTo(self).offset(-SPACING_EDGE);
  44. make.centerY.equalTo(self);
  45. make.width.equalTo(@8.0f);
  46. make.height.equalTo(@13.0f);
  47. }];
  48. [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.top.bottom.left.right.equalTo(self);
  50. }];
  51. [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.right.top.equalTo(self);
  53. make.height.equalTo(@LINE_HEIGHT);
  54. }];
  55. [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.right.bottom.equalTo(self);
  57. make.height.equalTo(@LINE_HEIGHT);
  58. }];
  59. }
  60. #pragma mark - Public
  61. - (void)setTitle:(NSString *)title {
  62. _title = title;
  63. self.titleLabel.text = title;
  64. }
  65. - (void)setTitleColor:(UIColor *)titleColor {
  66. _titleColor = titleColor;
  67. self.titleLabel.textColor = titleColor;
  68. }
  69. - (void)setIsClick:(BOOL)isClick {
  70. _isClick = isClick;
  71. self.button.hidden = !isClick;
  72. }
  73. - (void)setIsShowMoreImage:(BOOL)isShowMoreImage {
  74. _isShowMoreImage = isShowMoreImage;
  75. self.moreImageView.hidden = !isShowMoreImage;
  76. if (isShowMoreImage) {
  77. /// 显示更多
  78. _textFiledRightConstraint.equalTo(@(-(SPACING_EDGE + 8.0f + 5.0f)));
  79. }else {
  80. _textFiledRightConstraint.equalTo(@(-SPACING_EDGE));
  81. }
  82. }
  83. - (void)setIsShowTopLine:(BOOL)isShowTopLine {
  84. _isShowTopLine = isShowTopLine;
  85. self.topLine.hidden = !isShowTopLine;
  86. }
  87. - (void)setIsShowBottomLine:(BOOL)isShowBottomLine {
  88. _isShowBottomLine = isShowBottomLine;
  89. self.bottomLine.hidden = !isShowBottomLine;
  90. }
  91. - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents {
  92. self.button.hidden = NO;
  93. [self.button addTarget:target action:action forControlEvents:controlEvents];
  94. }
  95. - (void)setFont:(UIFont *)font {
  96. _font = font;
  97. self.titleLabel.font = font;
  98. }
  99. - (void)setPlaceholder:(NSString *)placeholder {
  100. _placeholder = placeholder;
  101. self.textField.placeholder = placeholder;
  102. }
  103. - (void)setMoreImag:(UIImage *)moreImag {
  104. _moreImag = moreImag;
  105. self.moreImageView.image = moreImag;
  106. }
  107. #pragma mark - Get/Set
  108. - (UILabel *)titleLabel {
  109. if (_titleLabel == nil) {
  110. _titleLabel = [[UILabel alloc] init];
  111. _titleLabel.font = Font(15);
  112. _titleLabel.textColor = Color_TextFont;
  113. }
  114. return _titleLabel;
  115. }
  116. - (UITextField *)textField {
  117. if (_textField == nil) {
  118. _textField = [[UITextField alloc] init];
  119. _textField.textColor = Color_TextFont;
  120. _textField.font = Font(15);
  121. _textField.textAlignment = NSTextAlignmentRight;
  122. }
  123. return _textField;
  124. }
  125. - (UIImageView *)moreImageView {
  126. if (_moreImageView == nil) {
  127. _moreImageView = [UIImageView new];
  128. _moreImageView.image = arrowMore();
  129. }
  130. return _moreImageView;
  131. }
  132. - (UIButton *)button {
  133. if (_button == nil) {
  134. _button = [UIButton buttonWithType:UIButtonTypeCustom];
  135. [_button setBackgroundColor:Color_Clear];
  136. }
  137. return _button;
  138. }
  139. - (UIView *)bottomLine {
  140. if (_bottomLine == nil) {
  141. _bottomLine = [UIView new];
  142. _bottomLine.backgroundColor = Color_line;
  143. }
  144. return _bottomLine;
  145. }
  146. - (UIView *)topLine {
  147. if (_topLine == nil) {
  148. _topLine = [UIView new];
  149. _topLine.backgroundColor = Color_line;
  150. _topLine.hidden = YES;
  151. }
  152. return _topLine;
  153. }
  154. @end