| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- //
- // MinePageHeadView.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/29.
- //
- #import "MinePageHeadView.h"
- #import "TeacherInfo.h"
- #import "KSStarView.h"
- @interface MinePageHeadView ()
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topHeight;
- @property (weak, nonatomic) IBOutlet UIImageView *userAvatar;
- @property (weak, nonatomic) IBOutlet UILabel *teacherName;
- @property (weak, nonatomic) IBOutlet UIView *subjectView;
- @property (weak, nonatomic) IBOutlet UIView *starBgView;
- @property (weak, nonatomic) IBOutlet UILabel *fansCount;
- @property (weak, nonatomic) IBOutlet UILabel *courseCount;
- @property (weak, nonatomic) IBOutlet KSStarView *starView;
- @property (nonatomic, copy) MinePageBack callback;
- @end
- @implementation MinePageHeadView
- - (void)awakeFromNib {
- [super awakeFromNib];
- self.starView.allowMark = NO;
- self.topHeight.constant = iPhoneXSafeTopMargin + 55;
- }
- + (instancetype)shareInstance {
- MinePageHeadView *view = [[[NSBundle mainBundle] loadNibNamed:@"MinePageHeadView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)configSource:(id)source {
- if ([source isKindOfClass:[TeacherInfo class]]) {
- TeacherInfo *infoMessage = source;
- [self displayCount:infoMessage.fansNum inView:self.fansCount];
- [self displayCount:infoMessage.expTime inView:self.courseCount];
- self.starView.rate = infoMessage.starGrade / 5.0f;
- if (![NSString isEmptyString:infoMessage.heardUrl]) {
- [self.userAvatar sd_setImageWithURL:[NSURL URLWithString:infoMessage.heardUrl] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- }
- else {
- [self.userAvatar setImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- }
- if ([NSString isEmptyString:infoMessage.username]) {
- self.teacherName.text = [NSString stringWithFormat:@"游客%@",infoMessage.userId];
- }
- else {
- self.teacherName.text = infoMessage.username;
- }
- if ([NSString isEmptyString:infoMessage.subjectName]) {
- [self.subjectView removeAllSubViews];
- }
- else {
- NSArray *tagArray = [infoMessage.subjectName componentsSeparatedByString:@","];
- CGFloat maxWidth = kScreenWidth - 28 - 10 - 80;
- [self configTagViewWithTagArray:tagArray maxWidth:maxWidth];
- }
-
- }
- }
- - (void)displayCount:(NSInteger)count inView:(UILabel *)descLabel {
- if (count > 10000) {
- double descNum = count / 10000.0;
- descLabel.text = [NSString stringWithFormat:@"%.2f万",descNum];
- }
- else {
- descLabel.text = [NSString stringWithFormat:@"%ld",count];
- }
- }
- - (void)backAction:(MinePageBack)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (IBAction)back:(id)sender {
- if (self.callback) {
- self.callback();
- }
- }
- - (CGFloat)getViewHeight {
- return self.topHeight.constant + 10 +22 + 30 + 128;
- }
- - (void)configTagViewWithTagArray:(NSArray *)tagArray maxWidth:(CGFloat)maxWidth {
- [self.subjectView removeAllSubViews];
- CGFloat width = maxWidth;
- CGFloat xSpace = 0.0f;
- for (NSInteger i = 0; i < tagArray.count; i++) {
- NSString *tagString = tagArray[i];
- CGFloat labelWidth = [self getStringWidthInLabel:tagString font:[UIFont systemFontOfSize:11.0f]];
- CGFloat viewWidth = labelWidth + 8;
- if (xSpace + viewWidth > width) {
- return;
- }
- CGRect frame = CGRectMake(xSpace, 0, viewWidth, 16.0f);
- [self createTagLabelViewWithName:tagString frame:frame];
- xSpace += (viewWidth + 6);
- }
- }
- - (CGFloat)getStringWidthInLabel:(NSString *)tagString font:(UIFont *)font {
- CGFloat width = [tagString boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 16.0f) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:font} context:nil].size.width+1;
- return width;
- }
- - (void)createTagLabelViewWithName:(NSString *)name frame:(CGRect)frame {
- UIView *bgView = [[UIView alloc] initWithFrame:frame];
- bgView.backgroundColor = HexRGB(0xfff1de);
- bgView.layer.cornerRadius = 4.0f;
- [self.subjectView addSubview:bgView];
-
- UILabel *tagLabel = [[UILabel alloc] init];
- tagLabel.text = name;
- tagLabel.textColor = HexRGB(0xff8c00);
- tagLabel.font = [UIFont systemFontOfSize:11.0f];
- tagLabel.textAlignment = NSTextAlignmentCenter;
- [bgView addSubview:tagLabel];
- [tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(bgView.mas_left).offset(4);
- make.right.mas_equalTo(bgView.mas_right).offset(-4);
- make.top.bottom.mas_equalTo(bgView);
- }];
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|