Browse Source

[*] 暂时提交

yanxuyao 5 tháng trước cách đây
mục cha
commit
5a93ee3a7a

+ 1 - 1
MiMoLive/MiMoLive/Classes/Live/View/MORightToLeftBannerView/MOEnterBarView/MOEnterShowView.m

@@ -77,7 +77,7 @@
         make.left.equalTo(self.headImgView.mas_right).offset(6.0);
         make.right.equalTo(self.bgView).offset(-16.0);
         make.height.equalTo(@14.0);
-        make.centerY.equalTo(self.bgView).offset(6.0);
+        make.centerY.equalTo(self.bgView).offset(8.0);
     }];
     
     [self addSubview:self.throughBtn];

+ 83 - 1
MiMoLive/MiMoLive/Global/MOTextTools.m

@@ -560,7 +560,7 @@
     }
     
     //加等级
-    [self toAddLevelInfoWith:plainText And:rtmEntity.user.level];
+    [self toAddSmallLevelInfoWith:plainText And:rtmEntity.user.level];
     
     return plainText;
 }
@@ -911,6 +911,88 @@
     }
 }
 
++ (NSMutableAttributedString *)toAddSmallLevelInfoWith:(NSMutableAttributedString *)contentStr And:(NSInteger)levelNum{
+    
+    NSArray *levelInfoArr = [MOSvgaSourceManage shareManager].allLevelSoureArr;
+    MOStoreInfo *medalInfo;
+    for (MOStoreInfo *object in levelInfoArr) {
+        if(levelNum >= object.limit){
+            medalInfo = object;
+            break;
+        }
+    }
+    
+    CGFloat levelHeight = 14.0;
+    
+    if(medalInfo.res.length > 0){
+        
+        //这里调整的话, 请同时调整 MOBaseLevelView
+        CGFloat levelWidth = MOLevelNormalWidth;
+        CGFloat levelLabelX = 14.0;
+        CGFloat levelLabexWidth = levelWidth - levelLabelX;
+        
+        if(levelNum >= 100){
+            levelWidth = MOLevelMaxWidth;
+            levelLabexWidth = levelWidth - levelLabelX - 5.0;
+        }
+        else if (levelNum < 10){
+            levelWidth = MOLevelMixWidth;
+            levelLabelX = 13.0;
+            levelLabexWidth = levelWidth - levelLabelX;
+        }
+
+        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, levelWidth, levelHeight)];
+        bgView.backgroundColor = [UIColor clearColor];
+        
+        YYAnimatedImageView *levelImg = [[YYAnimatedImageView alloc] init];
+        levelImg.frame = CGRectMake(0.0, 0.0, levelWidth, levelHeight);
+        levelImg.contentMode = UIViewContentModeScaleAspectFit;
+        NSURL *url = [NSURL URLWithString:medalInfo.res];
+        [levelImg setImageWithURL:url placeholder:nil];
+        [bgView addSubview:levelImg];
+        
+        UILabel *levelLabel = [[UILabel alloc] initWithFrame:CGRectMake(levelLabelX, 0, levelLabexWidth, levelHeight)];
+        levelLabel.font = [MOTextTools poppinsExtraBoldFont:10.0];
+        levelLabel.textColor = [UIColor whiteColor];
+        levelLabel.textAlignment = NSTextAlignmentCenter;
+        levelLabel.text = [NSString stringWithFormat:@"%zd",levelNum];
+        [bgView addSubview:levelLabel];
+        CGSize viewSize = bgView.size;
+        
+        NSMutableAttributedString *levelImgAttri = [NSMutableAttributedString attachmentStringWithContent:bgView contentMode:UIViewContentModeScaleAspectFit attachmentSize:viewSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
+        [levelImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
+
+        [contentStr insertAttributedString:[levelImgAttri copy] atIndex:0];
+        
+        return contentStr;
+    }
+    else{
+        UIImage *levelImg = [MOTextTools createLevelImageViewWith:levelNum];
+
+        CGSize levelSize;
+        //创建一个NSTextAttachment
+        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
+        attachment.image = levelImg;
+        //字体行高
+        UIFont *font = MOTextLabelFont;
+        CGFloat attachmentHeight = font.lineHeight;
+        CGFloat imgSizeHeight = GetParamNotZero(levelImg.size.height);
+        CGFloat attachmentWidth = attachmentHeight * levelImg.size.width/ imgSizeHeight;
+        attachment.bounds = CGRectMake(0, (font.capHeight-font.lineHeight)/2, attachmentWidth, attachmentHeight);
+        levelSize = CGSizeMake(attachmentWidth, attachmentHeight);
+        
+        //生成NSAttributedString
+        NSMutableAttributedString *levelImgAttri = [NSMutableAttributedString attachmentStringWithContent:levelImg contentMode:UIViewContentModeScaleAspectFit attachmentSize:levelSize alignToFont:MOTextLabelFont alignment:YYTextVerticalAlignmentCenter];
+    //    NSMutableAttributedString *levelImgAttri = [[NSAttributedString attributedStringWithAttachment:attachment] mutableCopy];
+        
+        [levelImgAttri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
+
+        [contentStr insertAttributedString:[levelImgAttri copy] atIndex:0];
+        
+        return contentStr;
+    }
+}
+
 //增加勋章
 + (NSMutableAttributedString *)toAddMedalInfoWith:(NSMutableAttributedString *)contentStr And:(NSArray *)medalList{