diff --git a/xplan-ios/Main/Mine/Model/XPMineFuntionItemModel.h b/xplan-ios/Main/Mine/Model/XPMineFuntionItemModel.h index f17e4339..0ba6f351 100644 --- a/xplan-ios/Main/Mine/Model/XPMineFuntionItemModel.h +++ b/xplan-ios/Main/Mine/Model/XPMineFuntionItemModel.h @@ -20,9 +20,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy) NSString *centerName; @property (nonatomic, copy) NSString *centerUrl; -///未读消息 -@property (nonatomic, assign) NSInteger unReadCount; - @end NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Main/Mine/View/SubViews/XPMineFriendNumberView.h b/xplan-ios/Main/Mine/View/SubViews/XPMineFriendNumberView.h index 1efac8f7..96683255 100644 --- a/xplan-ios/Main/Mine/View/SubViews/XPMineFriendNumberView.h +++ b/xplan-ios/Main/Mine/View/SubViews/XPMineFriendNumberView.h @@ -15,6 +15,10 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic,copy) NSString *number; ///显示标题 @property (nonatomic,copy) NSString *title; +///是否为访客记录 +@property (nonatomic, assign) BOOL isVisitor; +///访客角标 +@property (nonatomic, assign) NSInteger visitorNum; @end diff --git a/xplan-ios/Main/Mine/View/SubViews/XPMineFriendNumberView.m b/xplan-ios/Main/Mine/View/SubViews/XPMineFriendNumberView.m index aacd4a7f..987c13ca 100644 --- a/xplan-ios/Main/Mine/View/SubViews/XPMineFriendNumberView.m +++ b/xplan-ios/Main/Mine/View/SubViews/XPMineFriendNumberView.m @@ -10,12 +10,16 @@ #import ///Tool #import "ThemeColor.h" +#import @interface XPMineFriendNumberView () ///显示个数 @property (nonatomic,strong) UILabel *numberLabel; ///显示标题 @property (nonatomic,strong) UILabel *titleLabel; +//访客记录未读数量 +@property (nonatomic, strong) UILabel *unReadLabel; + @end @implementation XPMineFriendNumberView @@ -41,7 +45,8 @@ }]; [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) { - make.left.right.top.mas_equalTo(self); + make.top.mas_equalTo(self); + make.centerX.mas_equalTo(self); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { @@ -50,6 +55,23 @@ }]; } +- (NSAttributedString *)attributedStringWithLineSpace:(CGFloat)lineSpace str:(NSString *)str{ + NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] init]; + NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0xffffff), NSFontAttributeName: [UIFont systemFontOfSize:11]}]; + [attributedString appendAttributedString:title]; + attributedString.yy_alignment = NSTextAlignmentCenter; + return attributedString; +} + +- (CGFloat)getWidthWithContent:(NSString *)content height:(CGFloat)height font:(CGFloat)font{ + + CGRect rect = [content boundingRectWithSize:CGSizeMake(999, height) + options:NSStringDrawingUsesLineFragmentOrigin + attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} + context:nil]; + return rect.size.width; +} + #pragma mark - Getters And Setters - (void)setTitle:(NSString *)title { self.titleLabel.text = title; @@ -59,6 +81,37 @@ self.numberLabel.text = number; } +- (void)setIsVisitor:(BOOL)isVisitor { + if (isVisitor) { + [self addSubview:self.unReadLabel]; + [self.unReadLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.mas_equalTo(self.numberLabel.mas_right).mas_offset(5); + make.height.mas_equalTo(15); + make.width.mas_equalTo(15); + make.top.mas_equalTo(self.numberLabel); + }]; + } +} + +- (void)setVisitorNum:(NSInteger)visitorNum { + if (visitorNum > 0) { + self.unReadLabel.hidden = NO; + self.unReadLabel.attributedText = [self attributedStringWithLineSpace:10 str:[NSString stringWithFormat:@"%zd", visitorNum]]; + CGFloat width = [self getWidthWithContent:[NSString stringWithFormat:@"%zd", visitorNum] height:15 font:11]; + if (visitorNum < 10) { + width = 7; + } + [self.unReadLabel mas_remakeConstraints:^(MASConstraintMaker *make) { + make.left.mas_equalTo(self.numberLabel.mas_right).mas_offset(5); + make.width.mas_equalTo(width + 8); + make.top.mas_equalTo(self.numberLabel); + make.height.mas_equalTo(15); + }]; + } else { + self.unReadLabel.hidden = YES; + } +} + - (UILabel *)numberLabel { if (!_numberLabel) { _numberLabel = [[UILabel alloc] init]; @@ -79,4 +132,19 @@ return _titleLabel; } +- (UILabel *)unReadLabel { + if (!_unReadLabel) { + _unReadLabel = [[UILabel alloc] init]; + _unReadLabel.font = [UIFont systemFontOfSize:11]; + _unReadLabel.textColor = [UIColor whiteColor]; + _unReadLabel.backgroundColor = UIColorFromRGB(0xFF5B55); + _unReadLabel.layer.cornerRadius = 7.5; + _unReadLabel.layer.masksToBounds = YES; + _unReadLabel.textAlignment = NSTextAlignmentCenter; + [_unReadLabel sizeToFit]; + _unReadLabel.hidden = YES; + } + return _unReadLabel ; +} + @end diff --git a/xplan-ios/Main/Mine/View/SubViews/XPMineHeadView.h b/xplan-ios/Main/Mine/View/SubViews/XPMineHeadView.h index 831f64a2..7023ee67 100644 --- a/xplan-ios/Main/Mine/View/SubViews/XPMineHeadView.h +++ b/xplan-ios/Main/Mine/View/SubViews/XPMineHeadView.h @@ -34,6 +34,8 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong) WalletInfoModel *walletInfo; ///代理 @property (nonatomic,assign) id delegate; +///访客未读数量 +@property (nonatomic, assign) NSInteger visitorUnReadCount; @end NS_ASSUME_NONNULL_END diff --git a/xplan-ios/Main/Mine/View/SubViews/XPMineHeadView.m b/xplan-ios/Main/Mine/View/SubViews/XPMineHeadView.m index 90180750..ca61da41 100644 --- a/xplan-ios/Main/Mine/View/SubViews/XPMineHeadView.m +++ b/xplan-ios/Main/Mine/View/SubViews/XPMineHeadView.m @@ -437,6 +437,10 @@ self.accountView.diamonds = walletInfo.diamonds; } +- (void)setVisitorUnReadCount:(NSInteger)visitorUnReadCount { + self.visitorView.visitorNum = visitorUnReadCount; +} + - (NetImageView *)avatarImageView { if (!_avatarImageView) { NetImageConfig * config = [[NetImageConfig alloc]init]; @@ -573,6 +577,7 @@ if (!_visitorView) { _visitorView = [[XPMineFriendNumberView alloc] init]; _visitorView.title = @"访客"; + _visitorView.isVisitor = YES; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapVisitorRecognizer)]; [_visitorView addGestureRecognizer:tap]; } diff --git a/xplan-ios/Main/Mine/View/XPMineViewController.m b/xplan-ios/Main/Mine/View/XPMineViewController.m index bb9cccf2..e9b147fe 100644 --- a/xplan-ios/Main/Mine/View/XPMineViewController.m +++ b/xplan-ios/Main/Mine/View/XPMineViewController.m @@ -244,12 +244,7 @@ break; case XPMineItemType_Visitor: { - [self.tabBarItem setBadgeValue:nil]; - for (XPMineFuntionItemModel * model in self.functionArray) { - if (model.skipType == XPMineItemType_Visitor) { - model.unReadCount = 0; - } - } + self.headView.visitorUnReadCount = 0; XPMineVisitorViewController *visitorVC = [[XPMineVisitorViewController alloc] init]; [self.navigationController pushViewController:visitorVC animated:YES]; } @@ -517,19 +512,7 @@ #pragma mark - NSNotification - (void)onVisitorUnReadCountUpdate:(NSNotification *)noti { XPMineVisitorUnReadModel *model = (XPMineVisitorUnReadModel *)noti.object; - if (model.visitNum > 0) { - [self.tabBarItem setBadgeValue:[NSString stringWithFormat:@"%ld", model.visitNum]]; - } else { - [self.tabBarItem setBadgeValue:nil]; - } - - for (int i = 0; i