You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.0 KiB

2 years ago
//
// DeviceTabCollectionViewCell.m
// tongxin
//
// Created by ecell on 2023/6/16.
// Copyright © 2023 xTT. All rights reserved.
//
#import "DeviceTabCollectionViewCell.h"
@interface DeviceTabCollectionViewCell ()
@property (nonatomic ,weak) UIImageView *iconImg;
@property (nonatomic ,weak) UILabel *titleLabel;
@property (nonatomic ,weak) UILabel *msgNumLabel;
@end
@implementation DeviceTabCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = KKClearColor;
// self.layer.cornerRadius = 5;
// self.layer.masksToBounds = YES;
[self subhomeCell];
}
return self;
}
- (void)setImageName:(NSString *)imageName
{
_imageName = imageName;
self.iconImg.image = ImageName_(imageName);
}
- (void)setTitleName:(NSString *)titleName
{
_titleName = titleName;
self.titleLabel.text = titleName;
}
- (void)setChatMsgNum:(NSInteger)chatMsgNum
{
_chatMsgNum = chatMsgNum;
self.msgNumLabel.hidden = chatMsgNum > 0 && [self.titleName isEqualToString:@"微聊"] ? NO : YES;
if (chatMsgNum > 0)
{
self.msgNumLabel.text = chatMsgNum > 99 ? @"99+" : F(@"%ld", chatMsgNum);
CGFloat ww = chatMsgNum > 9 && chatMsgNum < 100 ? 25 : chatMsgNum > 99 ? 32 : 20;
[self.msgNumLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.iconImg.mas_right).offset(-10);
make.top.equalTo(self.iconImg).offset(-3);
make.size.mas_equalTo(CGSizeMake(ww, 20));
}];
}
}
- (void)subhomeCell
{
UIImageView *iconImg = [UIImageView new];
self.iconImg = iconImg;
[self.contentView addSubview:iconImg];
[iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.contentView);
make.top.equalTo(self.contentView).offset(5);
make.height.width.mas_equalTo(Adapted(30));
}];
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:KKTextColor text:@"" Radius:0];
self.titleLabel = titleLabel;
[self.contentView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self.contentView).inset(10);
make.top.equalTo(iconImg.mas_bottom).offset(10);
}];
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));
}];
}
@end