1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- //
- // HomeCountView.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2024/11/27.
- //
- #import "HomeCountView.h"
- @interface HomeCountView ()
- @property (nonatomic, copy) HomeCountCallback callback;
- @property (weak, nonatomic) IBOutlet UILabel *courseCountLabel;
- @property (weak, nonatomic) IBOutlet UILabel *timeLabel;
- @end
- @implementation HomeCountView
- + (instancetype)sharedInstance {
- HomeCountView *view = [[[NSBundle mainBundle] loadNibNamed:@"HomeCountView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)configWithSource:(NSDictionary *)parm {
- // 时间显示
- NSInteger duration = [parm ks_integerValueForKey:@"recordTime"];
- NSString *timeDesc = [NSString getTimeStringChineseWithTime:duration];
- UIFont *numberFont = [UIFont fontWithName:@"DIN Alternate Bold" size:22.0f];
- UIFont *nomalFont = [UIFont systemFontOfSize:12.0f weight:UIFontWeightRegular];
-
- // 计算两种字体的 descender 和 ascender 差异
- CGFloat maxDescender = MIN(numberFont.capHeight, nomalFont.descender);
-
- NSInteger baselineOffsetNumber = (maxDescender - numberFont.descender)/ 4.0f;
- NSInteger baselineOffsetNormal = (maxDescender - nomalFont.descender) / 4.0f;
- NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
- style.minimumLineHeight = 26;
- style.maximumLineHeight = 26;
- NSMutableAttributedString *attrs = [[NSMutableAttributedString alloc] initWithString:timeDesc attributes:@{NSFontAttributeName : numberFont,NSBaselineOffsetAttributeName:@(baselineOffsetNumber), NSForegroundColorAttributeName : HexRGB(0x333333), NSParagraphStyleAttributeName : style}];
- if ([timeDesc containsString:@" 时 "]) {
- [attrs addAttributes:@{NSFontAttributeName : nomalFont, NSBaselineOffsetAttributeName:@(baselineOffsetNormal), NSForegroundColorAttributeName:HexRGB(0x777777),NSParagraphStyleAttributeName : style} range:[timeDesc rangeOfString:@" 时 "]];
- }
- [attrs addAttributes:@{NSFontAttributeName : nomalFont, NSBaselineOffsetAttributeName:@(baselineOffsetNormal), NSForegroundColorAttributeName:HexRGB(0x777777),NSParagraphStyleAttributeName : style} range:[timeDesc rangeOfString:@" 分 "]];
- [attrs addAttributes:@{NSFontAttributeName : nomalFont, NSBaselineOffsetAttributeName:@(baselineOffsetNormal), NSForegroundColorAttributeName:HexRGB(0x777777),NSParagraphStyleAttributeName : style} range:[timeDesc rangeOfString:@" 秒"]];
- self.timeLabel.attributedText = attrs;
-
- self.courseCountLabel.text = [NSString stringWithFormat:@"%zd/%zd", [parm ks_integerValueForKey:@"courseCount"], [parm ks_integerValueForKey:@"totalCourseCount"]];
- }
- - (void)countActionCallback:(HomeCountCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (IBAction)showPractice:(id)sender {
- if (self.callback) {
- self.callback(NO);
- }
- }
- - (IBAction)showCourseTable:(id)sender {
- if (self.callback) {
- self.callback(YES);
- }
- }
- + (CGFloat)getViewHeight {
- CGFloat imageWidth = (KPortraitWidth - 14 * 2 - 9) / 2;
- CGFloat height = imageWidth / 169 * 67 + 12;
- return height;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|