XYPersonalCenterHeaderItemView.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // XYPersonalCenterHeaderItemView.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2019/12/23.
  6. // Copyright © 2019 翟玉磊. All rights reserved.
  7. //
  8. #import "XYPersonalCenterHeaderItemView.h"
  9. @interface XYPersonalCenterHeaderItemView ()
  10. @property (nonatomic, readwrite, strong) UILabel *visitNumLab;
  11. @end
  12. @implementation XYPersonalCenterHeaderItemView
  13. #pragma mark - Public Method
  14. - (void)setupTitle:(NSString *)title content:(NSString *)content {
  15. self.contentLabel.text = content;
  16. self.titleLabel.text = title;
  17. }
  18. #pragma mark - Private Method
  19. - (instancetype)init {
  20. if (self = [super init]) {
  21. // 初始化
  22. [self _setup];
  23. // 创建子控件
  24. [self _setupSubViews];
  25. // 布局子控件
  26. [self _makeSubViewsConstraints];
  27. }
  28. return self;
  29. }
  30. - (instancetype)initWithFrame:(CGRect)frame{
  31. if (self = [super initWithFrame:frame]) {
  32. // 初始化
  33. [self _setup];
  34. // 创建子控件
  35. [self _setupSubViews];
  36. // 布局子控件
  37. [self _makeSubViewsConstraints];
  38. }
  39. return self;
  40. }
  41. #pragma mark - 事件处理Or辅助方法
  42. - (void)itemButtonAction:(id)sender {
  43. if (self.itemClickActionBlock) {
  44. self.itemClickActionBlock(self.tag);
  45. }
  46. }
  47. #pragma mark - Private Method
  48. - (void)_setup{
  49. }
  50. - (void)setVisitFoot:(BOOL)visitFoot{
  51. _visitFoot = visitFoot;
  52. if (_visitFoot) {
  53. [[XYSocialApiManager new] getIntervieweeUnReadMsgCountSuccessHandler:^(ZYLResponseModel *responseModel) {
  54. NSString *str = [NSString stringWithFormat:@"%@",responseModel.data];
  55. NSInteger num = [str integerValue];
  56. if (num > 0) {
  57. self.visitNumLab.text = [NSString stringWithFormat:@"+%ld",num];
  58. }else{
  59. self.visitNumLab.text = @"";
  60. }
  61. } failureHandler:^(ZYLNetworkError *error) {
  62. }];
  63. }
  64. }
  65. #pragma mark - 创建子控件
  66. - (void)_setupSubViews{
  67. [self addSubview:self.contentLabel];
  68. [self addSubview:self.titleLabel];
  69. [self addSubview:self.lineView];
  70. [self addSubview:self.topLineView];
  71. [self addSubview:self.actionButton];
  72. [self.actionButton addTarget:self action:@selector(itemButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  73. }
  74. #pragma mark - 布局子控件
  75. - (void)_makeSubViewsConstraints{
  76. [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.centerX.equalTo(self);
  78. make.centerY.equalTo(self).offset(-12.0f);
  79. make.height.equalTo(@22.0f);
  80. }];
  81. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.centerX.equalTo(self);
  83. make.top.equalTo(self.contentLabel.mas_bottom).offset(2.0f);
  84. make.height.equalTo(@18.0f);
  85. }];
  86. [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.right.equalTo(self).offset(-1.0f);
  88. make.centerY.equalTo(self);
  89. make.width.equalTo(@1.f);
  90. make.height.equalTo(@23.0f);
  91. }];
  92. [self.topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.top.equalTo(self);
  94. make.right.equalTo(self).offset(-1.0f);
  95. make.height.equalTo(@1.0f);
  96. }];
  97. [self.actionButton mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.edges.equalTo(self);
  99. }];
  100. }
  101. - (UILabel *)contentLabel {
  102. if (!_contentLabel) {
  103. _contentLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(16)];
  104. _contentLabel.textAlignment = NSTextAlignmentCenter;
  105. }
  106. return _contentLabel;
  107. }
  108. - (UILabel *)titleLabel {
  109. if (!_titleLabel) {
  110. _titleLabel = [UILabel createLabelTextColor:Color_Nakaguro fount:Font(13)];
  111. _titleLabel.textAlignment = NSTextAlignmentCenter;
  112. }
  113. return _titleLabel;
  114. }
  115. - (UIImageView *)lineView {
  116. if (!_lineView) {
  117. _lineView = [UIImageView new];
  118. _lineView.backgroundColor = Color_Clear;
  119. }
  120. return _lineView;
  121. }
  122. - (UIImageView *)topLineView {
  123. if (!_topLineView) {
  124. _topLineView = [UIImageView new];
  125. _topLineView.backgroundColor = Color_Clear;
  126. }
  127. return _topLineView;
  128. }
  129. - (UIButton *)actionButton {
  130. if (!_actionButton) {
  131. _actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
  132. _actionButton.backgroundColor = Color_Clear;
  133. }
  134. return _actionButton;
  135. }
  136. - (UILabel *)visitNumLab{
  137. if (_visitNumLab== nil) {
  138. _visitNumLab = [[UILabel alloc] init];
  139. _visitNumLab.text = @"";
  140. _visitNumLab.textAlignment = NSTextAlignmentCenter;
  141. _visitNumLab.textColor = [UIColor colorWithHexString:@"#FF4281" alpha:1];
  142. _visitNumLab.font = [UIFont fontWithName:kPFSCFont size:12];
  143. [_visitNumLab sizeToFit];
  144. [self addSubview:_visitNumLab];
  145. [_visitNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
  146. make.left.equalTo(self.contentLabel.mas_right).offset(0);
  147. make.centerY.equalTo(self.contentLabel.mas_top).offset(0);
  148. }];
  149. }
  150. return _visitNumLab;
  151. }
  152. @end