123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- //
- // ShareMusicCellContentView.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/6/8.
- //
- #import "ShareMusicCellContentView.h"
- @interface ShareMusicCellContentView ()
- @property (weak, nonatomic) IBOutlet UILabel *songName;
- @property (weak, nonatomic) IBOutlet UILabel *songAuth;
- @property (weak, nonatomic) IBOutlet UIImageView *uploaderLogo;
- @property (weak, nonatomic) IBOutlet UILabel *uploaderName;
- @property (weak, nonatomic) IBOutlet UIImageView *typeImage;
- @property (weak, nonatomic) IBOutlet UIView *tagView;
- @property (weak, nonatomic) IBOutlet UIImageView *teacher_info;
- @end
- @implementation ShareMusicCellContentView
- + (instancetype)shareInstance {
- ShareMusicCellContentView *view = [[[NSBundle mainBundle] loadNibNamed:@"ShareMusicCellContentView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)configWithSongName:(NSString *)songName type:(NSString *)type authName:(NSString *)authName sendAvatar:(NSString *)sendAvatar sendName:(NSString *)sendName userId:(NSString *)userId tags:(NSString *)tags {
- self.songName.text = [NSString returnNoNullStringWithString:songName];
- self.songAuth.text = [NSString returnNoNullStringWithString:authName];
- NSArray *tagArray = [tags componentsSeparatedByString:@","];
- NSString *owner = @"";
- if ([NSString isEmptyString:sendName]) {
- owner = [NSString stringWithFormat:@"游客%@",userId];
- }
- else {
- owner = sendName;
- }
- CGFloat maxWidth = [self getTagViewMaxWidth:owner];
- [self configTagViewWithTagArray:tagArray maxWidth:maxWidth];
- NSString *typeImgName = @"";
- if ([type isEqualToString:@"VIP"]) {
- typeImgName = @"music_vip";
- }
- else if ([type isEqualToString:@"CHARGE"]) {
- typeImgName = @"music_order";
- }
- else {
- typeImgName = @"music_free";
- }
- [self.typeImage setImage:[UIImage imageNamed:typeImgName]];
-
- self.uploaderName.text = [NSString returnNoNullStringWithString:owner];
- [self.uploaderLogo sd_setImageWithURL:[NSURL URLWithString:[sendAvatar getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- }
- - (CGFloat)getTagViewMaxWidth:(NSString *)teacherName {
- CGFloat width = [self getStringWidthInLabel:teacherName font:[UIFont systemFontOfSize:12.0f]];
- return 260 - 45 - 10 - 14 - width - 8;
- }
- - (void)configTagViewWithTagArray:(NSArray *)tagArray maxWidth:(CGFloat)maxWidth {
- [self.tagView 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.tagView 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
|