12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- //
- // MyGroupCourseGroupTipsView.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2024/12/24.
- //
- #import "MyGroupCourseGroupTipsView.h"
- @interface MyGroupCourseGroupTipsView ()
- @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
- @end
- @implementation MyGroupCourseGroupTipsView
- + (instancetype)sharedInstance {
- MyGroupCourseGroupTipsView *view = [[[NSBundle mainBundle] loadNibNamed:@"MyGroupCourseGroupTipsView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)configWithMinStudentCount:(NSInteger)count {
- NSString *descString = [NSString stringWithFormat:@"该小组课销售截止后,报名人数若少于%zd人将取消开课,已购买学员付费金额将自动返还,请您放心购买",count];
- NSMutableParagraphStyle *paragraphStyle = [MyGroupCourseGroupTipsView getParagraphStyleWithFont:[UIFont systemFontOfSize:12.0f] lineHeight:23.0f];
- CGFloat baselineOffset = [MyGroupCourseGroupTipsView getBaseOffline:[UIFont systemFontOfSize:12.0f] lineHeight:23.0f];
- NSMutableAttributedString *introduceAttrs = [[NSMutableAttributedString alloc] initWithString:descString attributes:@{NSParagraphStyleAttributeName:paragraphStyle, NSBaselineOffsetAttributeName:@(baselineOffset),NSFontAttributeName:[UIFont systemFontOfSize:12.0f], NSForegroundColorAttributeName:HexRGB(0x777777)}];
- self.tipsLabel.attributedText = introduceAttrs;
- }
- + (CGFloat)getViewHeightWithCount:(NSInteger)count {
- NSString *descString = [NSString stringWithFormat:@"该小组课销售截止后,报名人数若少于%zd人将取消开课,已购买学员付费金额将自动返还,请您放心购买",count];
- return 54 + 30 + [self getViewRealHeight:descString];
- }
- + (CGFloat)getBaseOffline:(UIFont *)font lineHeight:(CGFloat)lineHeight {
- CGFloat descender = fabs(font.descender); // descender 为负值,取绝对值
- CGFloat ascender = font.ascender;
- CGFloat fontHeight = ascender + descender;
- CGFloat offset = (lineHeight - fontHeight) / 2.0; // 假设上下均等分布
- return offset;
- }
- + (NSMutableParagraphStyle *)getParagraphStyleWithFont:(UIFont *)font lineHeight:(CGFloat)lineHeigh {
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- paragraphStyle.maximumLineHeight = lineHeigh;
- paragraphStyle.minimumLineHeight = lineHeigh;
- return paragraphStyle;
- }
- + (CGFloat)getViewRealHeight:(NSString *)descString {
- NSMutableParagraphStyle *paragraphStyle = [self getParagraphStyleWithFont:[UIFont systemFontOfSize:12.0f] lineHeight:23.0f];
- CGFloat baselineOffset = [self getBaseOffline:[UIFont systemFontOfSize:12.0f] lineHeight:23.0f];
- CGFloat height = [descString boundingRectWithSize:CGSizeMake(KPortraitWidth - 26, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSParagraphStyleAttributeName:paragraphStyle, NSBaselineOffsetAttributeName:@(baselineOffset),NSFontAttributeName:[UIFont systemFontOfSize:12.0f]} context:nil].size.height + 1;
- 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
|