// // MenuCollectionViewCell.m // LekangGuard // // Created by ecell on 2022/10/25. // #import "MenuCollectionViewCell.h" @interface MenuCollectionViewCell () @property (nonatomic ,weak) UIImageView *iconImg; @property (nonatomic ,weak) UILabel *titleLabel; @property (nonatomic ,weak) UILabel *msgNumLabel; @end @implementation MenuCollectionViewCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = KKClearColor; [self subMenuCell]; } return self; } - (void)setTitleStr:(NSString *)titleStr { _titleStr = titleStr; self.titleLabel.text = titleStr; } - (void)setImgStr:(NSString *)imgStr { _imgStr = imgStr; self.iconImg.image = ImageName_(imgStr); } - (void)setChatCoutn:(NSInteger)chatCoutn { _chatCoutn = chatCoutn; self.msgNumLabel.hidden = YES; if ([self.titleStr isEqualToString:@"微聊"]) { self.msgNumLabel.hidden = chatCoutn > 0 ? NO : YES; self.msgNumLabel.text = [NSString stringWithFormat:@"%ld",chatCoutn]; if (chatCoutn > 0) { CGFloat ww = chatCoutn > 9 && chatCoutn < 100 ? 25 : chatCoutn > 99 ? 32 : 20; [self.msgNumLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.iconImg.mas_right).offset(5); make.top.equalTo(self.iconImg); make.size.mas_equalTo(CGSizeMake(ww, 20)); }]; } } } - (void)setMunberCoutn:(NSInteger)munberCoutn { _munberCoutn = munberCoutn; self.msgNumLabel.hidden = YES; if ([self.titleStr isEqualToString:@"成员管理"]) { self.msgNumLabel.hidden = munberCoutn > 0 ? NO : YES; self.msgNumLabel.text = [NSString stringWithFormat:@"%ld",munberCoutn]; if (munberCoutn > 0) { CGFloat ww = munberCoutn > 9 && munberCoutn < 100 ? 25 : munberCoutn > 99 ? 32 : 20; [self.msgNumLabel mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.iconImg.mas_right).offset(5); make.top.equalTo(self.iconImg); make.size.mas_equalTo(CGSizeMake(ww, 20)); }]; } } } - (void)subMenuCell { UIImage *img = ImageName_(@"icon_watch_data"); UIImageView *iconImg = [UICommon ui_imageView:CGRectZero fileName:@""]; self.iconImg = iconImg; [self.contentView addSubview:iconImg]; [iconImg mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(Adapted(10)); make.centerX.equalTo(self.contentView); make.size.mas_equalTo(CGSizeMake(Adapted(img.size.width), Adapted(img.size.height))); }]; UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(12) textColor:KKTextBlackColor text:@"" Radius:0]; self.titleLabel = titleLabel; [self.contentView addSubview:titleLabel]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.equalTo(self.contentView.mas_bottom).inset(Adapted(10)); make.centerX.equalTo(self.contentView); }]; UILabel *msgNumLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(13) textColor:KKWhiteColorColor text:@"" Radius:10]; msgNumLabel.layer.borderWidth = 1.5; msgNumLabel.layer.borderColor = KKWhiteColorColor.CGColor; msgNumLabel.backgroundColor = RGB(254, 83, 71); msgNumLabel.hidden = YES; self.msgNumLabel = msgNumLabel; [self.contentView addSubview:msgNumLabel]; [msgNumLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(iconImg.mas_right).offset(3); make.top.equalTo(iconImg).offset(-3); make.size.mas_equalTo(CGSizeMake(20, 20)); }]; // UILabel *line = [UILabel new]; // line.backgroundColor = KKLineColor; // [self.contentView addSubview:line]; // [line mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.right.equalTo(self.contentView); // make.bottom.equalTo(self.contentView.mas_bottom); // make.height.mas_equalTo(0.5); // }]; } @end