个人中心-访客记录角标

This commit is contained in:
chenguilong
2022-07-27 11:49:51 +08:00
parent 332ace4cb9
commit 41a73df7fb
6 changed files with 82 additions and 23 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -10,12 +10,16 @@
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor.h"
#import <YYText/YYText.h>
@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

View File

@@ -34,6 +34,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong) WalletInfoModel *walletInfo;
///代理
@property (nonatomic,assign) id<XPMineHeadViewDelegate> delegate;
///访客未读数量
@property (nonatomic, assign) NSInteger visitorUnReadCount;
@end
NS_ASSUME_NONNULL_END

View File

@@ -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];
}

View File

@@ -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<self.functionArray.count; i++) {
XPMineFuntionItemModel * item = [self.functionArray objectAtIndex:i];
if (item.skipType == XPMineItemType_Visitor) {
item.unReadCount = model.visitNum;
}
}
[self.tableView reloadData];
self.headView.visitorUnReadCount = model.visitNum;
}
#pragma mark - Getters And Setters