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.
 
 
 

145 lines
4.5 KiB

//
// MyTableViewCell.m
// tongxin
//
// Created by ecell on 2023/6/21.
// Copyright © 2023 xTT. All rights reserved.
//
#import "MyTableViewCell.h"
#import "DPClearCacheTool.h"
@interface MyTableViewCell ()
@property (nonatomic ,weak) UIImageView *iconImg;
@property (nonatomic ,weak) UILabel *titleLabel;
/// 未读消息展示红点
@property (nonatomic ,weak) UILabel *newsMeg;
///缓存显示
@property (nonatomic ,weak) UILabel *cacheLabel;
@property (nonatomic ,weak) UIImageView *rightImg;
@end
@implementation MyTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = KKWhiteColorColor;
[self subCellView];
}
return self;
}
- (void)setImageName:(NSString *)imageName
{
_imageName = imageName;
self.iconImg.image = ImageName_(imageName);
}
- (void)setTitleName:(NSString *)titleName
{
_titleName = titleName;
self.titleLabel.text = titleName;
if ([titleName isEqualToString:@"清除缓存"])
self.cacheLabel.text = [DPClearCacheTool getCacheSize];
self.cacheLabel.hidden = [titleName isEqualToString:@"清除缓存"] ? NO : YES;
}
- (void)setMessageCount:(NSInteger )messageCount
{
_messageCount = messageCount;
self.newsMeg.hidden = YES;
if ([self.titleName isEqualToString:@"消息中心"])
{
self.newsMeg.hidden = messageCount > 0 ? NO : YES;
self.newsMeg.text = [NSString stringWithFormat:@"%ld",messageCount];
if (messageCount > 0)
{
CGFloat ww = messageCount > 9 && messageCount < 100 ? 25 : messageCount > 99 ? 32 : 20;
[self.newsMeg mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.rightImg.mas_left).inset(15);
make.centerY.equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(ww, 20));
}];
}
}
}
- (void)subCellView
{
UIImageView *iconImg = [UIImageView new];
self.iconImg = iconImg;
[self.contentView addSubview:iconImg];
[iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(25);
make.centerY.equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(22, 22));
}];
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(16) textColor:KKTextBlackColor text:@"" Radius:0];
self.titleLabel = titleLabel;
[self.contentView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(iconImg.mas_right).offset(19);
make.centerY.equalTo(self.contentView);
}];
UIImageView *rightImg = [UICommon ui_imageView:CGRectZero fileName:@"icon_enter_gray"];
self.rightImg = rightImg;
[self.contentView addSubview:rightImg];
[rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView.mas_right).inset(29);
make.centerY.equalTo(self.contentView);
make.size.mas_equalTo(rightImg.image.size);
}];
/// 未读消息展示红点
UILabel *newsMeg = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(12) textColor:KKWhiteColorColor text:@"" Radius:10];
newsMeg.backgroundColor = UIColor.redColor;
newsMeg.hidden = YES;
self.newsMeg = newsMeg;
[self.contentView addSubview:newsMeg];
[newsMeg mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(rightImg.mas_left).inset(15);
make.centerY.equalTo(self.contentView);
make.width.height.mas_equalTo(20);
}];
///缓存显示
UILabel *cacheLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontADA_(12) textColor:KKGrey121 text:[DPClearCacheTool getCacheSize] Radius:0];
cacheLabel.hidden = YES;
self.cacheLabel = cacheLabel;
[self.contentView addSubview:cacheLabel];
[cacheLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(rightImg.mas_left).inset(15);
make.centerY.equalTo(self.contentView);
}];
}
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end