2025-10-28 14:30:03 +08:00
|
|
|
|
//
|
|
|
|
|
|
// KBFunctionTagCell.m
|
|
|
|
|
|
// CustomKeyboard
|
|
|
|
|
|
//
|
|
|
|
|
|
// Created by Codex on 2025/10/28.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#import "KBFunctionTagCell.h"
|
|
|
|
|
|
#import "Masonry.h"
|
|
|
|
|
|
|
|
|
|
|
|
@interface KBFunctionTagCell ()
|
2025-12-08 16:39:47 +08:00
|
|
|
|
@property (nonatomic, strong) UILabel *emojiLabel;
|
2025-10-28 14:30:03 +08:00
|
|
|
|
@property (nonatomic, strong) UILabel *titleLabelInternal;
|
2025-11-12 16:49:19 +08:00
|
|
|
|
@property (nonatomic, strong) UIActivityIndicatorView *loadingView;
|
2025-10-28 14:30:03 +08:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation KBFunctionTagCell
|
|
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
|
|
|
|
if (self = [super initWithFrame:frame]) {
|
|
|
|
|
|
self.contentView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
|
|
|
|
|
|
self.contentView.layer.cornerRadius = 12;
|
|
|
|
|
|
self.contentView.layer.masksToBounds = YES;
|
|
|
|
|
|
|
2025-11-26 21:16:56 +08:00
|
|
|
|
// 小菊花:默认隐藏,放在整体内容右侧偏内的位置
|
|
|
|
|
|
[self.contentView addSubview:self.loadingView];
|
|
|
|
|
|
[self.loadingView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.center.equalTo(self.contentView);
|
|
|
|
|
|
make.width.height.mas_equalTo(16);
|
|
|
|
|
|
}];
|
2025-10-28 14:30:03 +08:00
|
|
|
|
|
2025-11-26 21:16:56 +08:00
|
|
|
|
// 中心容器:将 icon + title 组合整体水平居中
|
|
|
|
|
|
UIView *centerContainer = [[UIView alloc] init];
|
|
|
|
|
|
centerContainer.backgroundColor = [UIColor clearColor];
|
|
|
|
|
|
[self.contentView addSubview:centerContainer];
|
|
|
|
|
|
[centerContainer mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
|
make.centerX.equalTo(self.contentView.mas_centerX);
|
2025-10-28 14:30:03 +08:00
|
|
|
|
make.centerY.equalTo(self.contentView.mas_centerY);
|
2025-11-26 21:16:56 +08:00
|
|
|
|
make.left.greaterThanOrEqualTo(self.contentView.mas_left).offset(6);
|
|
|
|
|
|
make.right.lessThanOrEqualTo(self.contentView).offset(-6);
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
2025-12-08 16:39:47 +08:00
|
|
|
|
[centerContainer addSubview:self.emojiLabel];
|
2025-11-26 21:16:56 +08:00
|
|
|
|
[centerContainer addSubview:self.titleLabelInternal];
|
|
|
|
|
|
|
2025-12-08 16:39:47 +08:00
|
|
|
|
[self.emojiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
2025-11-26 21:16:56 +08:00
|
|
|
|
make.left.equalTo(centerContainer.mas_left);
|
|
|
|
|
|
make.centerY.equalTo(centerContainer.mas_centerY);
|
|
|
|
|
|
// 留出一点余量,避免 emoji 字形在右侧被裁剪
|
2025-10-28 14:30:03 +08:00
|
|
|
|
make.width.height.mas_equalTo(24);
|
|
|
|
|
|
}];
|
|
|
|
|
|
[self.titleLabelInternal mas_makeConstraints:^(MASConstraintMaker *make) {
|
2025-12-08 16:39:47 +08:00
|
|
|
|
make.left.equalTo(self.emojiLabel.mas_right).offset(3);
|
2025-11-26 21:16:56 +08:00
|
|
|
|
make.top.equalTo(centerContainer.mas_top);
|
|
|
|
|
|
make.bottom.equalTo(centerContainer.mas_bottom);
|
|
|
|
|
|
make.right.equalTo(centerContainer.mas_right);
|
2025-11-12 16:49:19 +08:00
|
|
|
|
}];
|
2025-10-28 14:30:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
return self;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-08 16:39:47 +08:00
|
|
|
|
- (void)setItemModel:(KBTagItemModel *)itemModel{
|
|
|
|
|
|
_itemModel = itemModel;
|
|
|
|
|
|
self.emojiLabel.text = itemModel.emoji;
|
|
|
|
|
|
self.titleLabelInternal.text = itemModel.characterName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-28 14:30:03 +08:00
|
|
|
|
#pragma mark - Lazy
|
|
|
|
|
|
|
2025-12-08 16:39:47 +08:00
|
|
|
|
- (UILabel *)emojiLabel {
|
|
|
|
|
|
if (!_emojiLabel) {
|
|
|
|
|
|
_emojiLabel = [[UILabel alloc] init];
|
|
|
|
|
|
_emojiLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
|
_emojiLabel.font = [KBFont medium:20];
|
|
|
|
|
|
_emojiLabel.adjustsFontSizeToFitWidth = YES;
|
|
|
|
|
|
|
2025-10-28 14:30:03 +08:00
|
|
|
|
}
|
2025-12-08 16:39:47 +08:00
|
|
|
|
return _emojiLabel;
|
2025-10-28 14:30:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (UILabel *)titleLabelInternal {
|
|
|
|
|
|
if (!_titleLabelInternal) {
|
|
|
|
|
|
_titleLabelInternal = [[UILabel alloc] init];
|
2025-11-26 21:16:56 +08:00
|
|
|
|
_titleLabelInternal.font = [KBFont medium:10];
|
|
|
|
|
|
_titleLabelInternal.textColor = [UIColor colorWithHex:0x1B1F1A];
|
|
|
|
|
|
// 最多两行,文本过长时末尾截断
|
|
|
|
|
|
_titleLabelInternal.numberOfLines = 2;
|
|
|
|
|
|
_titleLabelInternal.lineBreakMode = NSLineBreakByTruncatingTail;
|
2025-10-28 14:30:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
return _titleLabelInternal;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-12 16:49:19 +08:00
|
|
|
|
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
|
|
|
|
|
|
static UIActivityIndicatorViewStyle KBSpinnerStyle(void) { return UIActivityIndicatorViewStyleMedium; }
|
|
|
|
|
|
#else
|
|
|
|
|
|
static UIActivityIndicatorViewStyle KBSpinnerStyle(void) { return UIActivityIndicatorViewStyleGray; }
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
- (UIActivityIndicatorView *)loadingView {
|
|
|
|
|
|
if (!_loadingView) {
|
|
|
|
|
|
_loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:KBSpinnerStyle()];
|
|
|
|
|
|
_loadingView.hidesWhenStopped = YES;
|
|
|
|
|
|
_loadingView.color = [UIColor grayColor];
|
|
|
|
|
|
_loadingView.hidden = YES;
|
|
|
|
|
|
}
|
|
|
|
|
|
return _loadingView;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-28 14:30:03 +08:00
|
|
|
|
#pragma mark - Expose
|
|
|
|
|
|
|
|
|
|
|
|
- (UILabel *)titleLabel { return self.titleLabelInternal; }
|
|
|
|
|
|
|
2025-11-12 16:49:19 +08:00
|
|
|
|
- (void)setLoading:(BOOL)loading {
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
|
self.loadingView.hidden = NO;
|
|
|
|
|
|
[self.loadingView startAnimating];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
[self.loadingView stopAnimating];
|
|
|
|
|
|
self.loadingView.hidden = YES;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-28 14:30:03 +08:00
|
|
|
|
|
2025-11-12 16:49:19 +08:00
|
|
|
|
@end
|