123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- //
- // XYPersonalCenterHeaderItemView.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2019/12/23.
- // Copyright © 2019 翟玉磊. All rights reserved.
- //
- #import "XYPersonalCenterHeaderItemView.h"
- @interface XYPersonalCenterHeaderItemView ()
- @property (nonatomic, readwrite, strong) UILabel *visitNumLab;
- @end
- @implementation XYPersonalCenterHeaderItemView
- #pragma mark - Public Method
- - (void)setupTitle:(NSString *)title content:(NSString *)content {
- self.contentLabel.text = content;
- self.titleLabel.text = title;
- }
- #pragma mark - Private Method
- - (instancetype)init {
- if (self = [super init]) {
- // 初始化
- [self _setup];
-
- // 创建子控件
- [self _setupSubViews];
-
- // 布局子控件
- [self _makeSubViewsConstraints];
- }
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- // 初始化
- [self _setup];
-
- // 创建子控件
- [self _setupSubViews];
-
- // 布局子控件
- [self _makeSubViewsConstraints];
- }
- return self;
- }
- #pragma mark - 事件处理Or辅助方法
- - (void)itemButtonAction:(id)sender {
- if (self.itemClickActionBlock) {
- self.itemClickActionBlock(self.tag);
- }
- }
- #pragma mark - Private Method
- - (void)_setup{
-
- }
- - (void)setVisitFoot:(BOOL)visitFoot{
- _visitFoot = visitFoot;
- if (_visitFoot) {
- [[XYSocialApiManager new] getIntervieweeUnReadMsgCountSuccessHandler:^(ZYLResponseModel *responseModel) {
- NSString *str = [NSString stringWithFormat:@"%@",responseModel.data];
- NSInteger num = [str integerValue];
- if (num > 0) {
- self.visitNumLab.text = [NSString stringWithFormat:@"+%ld",num];
- }else{
- self.visitNumLab.text = @"";
- }
- } failureHandler:^(ZYLNetworkError *error) {
- }];
- }
- }
- #pragma mark - 创建子控件
- - (void)_setupSubViews{
- [self addSubview:self.contentLabel];
- [self addSubview:self.titleLabel];
- [self addSubview:self.lineView];
- [self addSubview:self.topLineView];
- [self addSubview:self.actionButton];
-
- [self.actionButton addTarget:self action:@selector(itemButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
- [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.centerY.equalTo(self).offset(-12.0f);
- make.height.equalTo(@22.0f);
- }];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.top.equalTo(self.contentLabel.mas_bottom).offset(2.0f);
- make.height.equalTo(@18.0f);
- }];
- [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self).offset(-1.0f);
- make.centerY.equalTo(self);
- make.width.equalTo(@1.f);
- make.height.equalTo(@23.0f);
- }];
- [self.topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.equalTo(self);
- make.right.equalTo(self).offset(-1.0f);
- make.height.equalTo(@1.0f);
- }];
- [self.actionButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
- }
- - (UILabel *)contentLabel {
- if (!_contentLabel) {
- _contentLabel = [UILabel createLabelTextColor:Color_TextFont fount:Font_B(16)];
- _contentLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _contentLabel;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [UILabel createLabelTextColor:Color_Nakaguro fount:Font(13)];
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _titleLabel;
- }
- - (UIImageView *)lineView {
- if (!_lineView) {
- _lineView = [UIImageView new];
- _lineView.backgroundColor = Color_Clear;
- }
- return _lineView;
- }
- - (UIImageView *)topLineView {
- if (!_topLineView) {
- _topLineView = [UIImageView new];
- _topLineView.backgroundColor = Color_Clear;
- }
- return _topLineView;
- }
- - (UIButton *)actionButton {
- if (!_actionButton) {
- _actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _actionButton.backgroundColor = Color_Clear;
- }
- return _actionButton;
- }
- - (UILabel *)visitNumLab{
- if (_visitNumLab== nil) {
- _visitNumLab = [[UILabel alloc] init];
- _visitNumLab.text = @"";
- _visitNumLab.textAlignment = NSTextAlignmentCenter;
- _visitNumLab.textColor = [UIColor colorWithHexString:@"#FF4281" alpha:1];
- _visitNumLab.font = [UIFont fontWithName:kPFSCFont size:12];
- [_visitNumLab sizeToFit];
- [self addSubview:_visitNumLab];
- [_visitNumLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentLabel.mas_right).offset(0);
- make.centerY.equalTo(self.contentLabel.mas_top).offset(0);
- }];
- }
- return _visitNumLab;
- }
- @end
|