This commit is contained in:
2025-12-15 18:02:58 +08:00
parent 9cafb0f70e
commit 053001170a
5 changed files with 64 additions and 38 deletions

View File

@@ -0,0 +1,17 @@
//
// KBEmojiCollectionCell.h
// CustomKeyboard
//
// Created by Mac on 2025/12/15.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface KBEmojiCollectionCell : UICollectionViewCell
@property (nonatomic, strong) UILabel *emojiLabel;
- (void)configureWithEmoji:(NSString *)emoji;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,38 @@
//
// KBEmojiCollectionCell.m
// CustomKeyboard
//
// Created by Mac on 2025/12/15.
//
#import "KBEmojiCollectionCell.h"
@implementation KBEmojiCollectionCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
_emojiLabel = [[UILabel alloc] init];
_emojiLabel.font = [UIFont systemFontOfSize:32];
_emojiLabel.textAlignment = NSTextAlignmentCenter;
_emojiLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_emojiLabel];
[NSLayoutConstraint activateConstraints:@[
[_emojiLabel.topAnchor constraintEqualToAnchor:self.contentView.topAnchor],
[_emojiLabel.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor],
[_emojiLabel.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor],
[_emojiLabel.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor],
]];
self.contentView.layer.cornerRadius = 10;
self.contentView.layer.masksToBounds = YES;
}
return self;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.emojiLabel.text = @"";
}
- (void)configureWithEmoji:(NSString *)emoji {
self.emojiLabel.text = emoji ?: @"";
}
@end

View File

@@ -8,43 +8,8 @@
#import "KBSkinManager.h"
#import "KBLocalizationManager.h"
#import "Masonry.h"
#import "KBEmojiCollectionCell.h"
@interface KBEmojiCollectionCell : UICollectionViewCell
@property (nonatomic, strong) UILabel *emojiLabel;
- (void)configureWithEmoji:(NSString *)emoji;
@end
@implementation KBEmojiCollectionCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
_emojiLabel = [[UILabel alloc] init];
_emojiLabel.font = [UIFont systemFontOfSize:32];
_emojiLabel.textAlignment = NSTextAlignmentCenter;
_emojiLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_emojiLabel];
[NSLayoutConstraint activateConstraints:@[
[_emojiLabel.topAnchor constraintEqualToAnchor:self.contentView.topAnchor],
[_emojiLabel.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor],
[_emojiLabel.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor],
[_emojiLabel.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor],
]];
self.contentView.layer.cornerRadius = 10;
self.contentView.layer.masksToBounds = YES;
}
return self;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.emojiLabel.text = @"";
}
- (void)configureWithEmoji:(NSString *)emoji {
self.emojiLabel.text = emoji ?: @"";
}
@end
@interface KBEmojiPanelView () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>