This commit is contained in:
2025-12-23 14:02:44 +08:00
parent 6ad2079351
commit 2e1c261775
9 changed files with 23 additions and 9 deletions

View File

@@ -5,6 +5,8 @@
#import "KBTagCell.h"
static const CGFloat kKBTagMinWidth = 50.0;
@interface KBTagCell ()
@property (nonatomic, strong) UILabel *titleLabel;
@end
@@ -29,10 +31,11 @@
}
+ (CGSize)sizeForText:(NSString *)text {
if (text.length == 0) { return CGSizeMake(40, 32); }
if (text.length == 0) { return CGSizeMake(kKBTagMinWidth, 32); }
CGSize s = [text sizeWithAttributes:@{NSFontAttributeName:[KBFont regular:13]}];
// 12 + 12 32
return CGSizeMake(ceil(s.width) + 24, 32);
CGFloat width = ceil(s.width) + 24;
return CGSizeMake(MAX(width, kKBTagMinWidth), 32);
}
#pragma mark - Lazy
@@ -42,9 +45,9 @@
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [KBFont regular:13];
_titleLabel.textColor = [UIColor colorWithHex:0x1B1F1A];
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
return _titleLabel;
}
@end