Commit 866a6e725ca1b36db82f84869dbaaa9ee09e9efd

Authored by zhangxiaowen
1 parent 939d145e

no message

CNLiveMineModule/Classes/View/CNLiveMineHeaderView.m
@@ -52,10 +52,10 @@ static const NSInteger margin = 20; @@ -52,10 +52,10 @@ static const NSInteger margin = 20;
52 [_header sd_setImageWithURL:[NSURL URLWithString:info] placeholderImage:xw_image]; 52 [_header sd_setImageWithURL:[NSURL URLWithString:info] placeholderImage:xw_image];
53 53
54 }else if(type == CNLiveUserInfoDataTypeNickname){ 54 }else if(type == CNLiveUserInfoDataTypeNickname){
55 - _name.attributedText = [self createAttributedImageName:@"mine_code" string:info font:16.0 isFront:NO]; 55 + _name.attributedText = [self createAttributedImageName:@"mine_code" string:info fontSize:16.0 isFront:NO];
56 56
57 }else if(type == CNLiveUserInfoDataTypeAddress){ 57 }else if(type == CNLiveUserInfoDataTypeAddress){
58 - _address.attributedText = [self createAttributedImageName:@"mine_location" string:info font:13.0 isFront:YES]; 58 + _address.attributedText = [self createAttributedImageName:@"mine_location" string:info fontSize:13.0 isFront:YES];
59 59
60 } 60 }
61 } 61 }
@@ -143,8 +143,8 @@ static const NSInteger margin = 20; @@ -143,8 +143,8 @@ static const NSInteger margin = 20;
143 - (void)setIsRefresh:(BOOL)isRefresh{ 143 - (void)setIsRefresh:(BOOL)isRefresh{
144 _isRefresh = isRefresh; 144 _isRefresh = isRefresh;
145 if(isRefresh){ 145 if(isRefresh){
146 - _name.attributedText = [self createAttributedImageName:@"mine_code" string:CNUserShareModel.nickname font:16.0 isFront:NO];  
147 - _address.attributedText = [self createAttributedImageName:@"mine_location" string:CNUserShareModel.location font:13.0 isFront:YES]; 146 + _name.attributedText = [self createAttributedImageName:@"mine_code" string:CNUserShareModel.nickname fontSize:16.0 isFront:NO];
  147 + _address.attributedText = [self createAttributedImageName:@"mine_location" string:CNUserShareModel.location fontSize:13.0 isFront:YES];
148 } 148 }
149 } 149 }
150 150
@@ -160,7 +160,7 @@ static const NSInteger margin = 20; @@ -160,7 +160,7 @@ static const NSInteger margin = 20;
160 } 160 }
161 */ 161 */
162 #pragma mark - Private Methods 162 #pragma mark - Private Methods
163 -- (NSMutableAttributedString *)createAttributedImageName:(NSString *)imageName string:(NSString *)string font:(CGFloat)font isFront:(BOOL)isFront{ 163 +- (NSMutableAttributedString *)createAttributedImageName:(NSString *)imageName string:(NSString *)string fontSize:(CGFloat)fontSize isFront:(BOOL)isFront{
164 if(isFront){ 164 if(isFront){
165 string = [NSString stringWithFormat:@" %@",string]; 165 string = [NSString stringWithFormat:@" %@",string];
166 } 166 }
@@ -168,25 +168,24 @@ static const NSInteger margin = 20; @@ -168,25 +168,24 @@ static const NSInteger margin = 20;
168 NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:string]; 168 NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:string];
169 // 修改富文本中的不同文字的样式 169 // 修改富文本中的不同文字的样式
170 // [attri addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, string.length)]; 170 // [attri addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, string.length)];
171 - [attri addAttribute:NSFontAttributeName value:UIFontCNMake(font) range:NSMakeRange(0, string.length)]; 171 + UIFont *font = UIFontCNMake(fontSize);
  172 + [attri addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, string.length)];
172 // 2.添加表情图片 173 // 2.添加表情图片
173 NSTextAttachment *attch = [[NSTextAttachment alloc] init]; 174 NSTextAttachment *attch = [[NSTextAttachment alloc] init];
174 // 表情图片 175 // 表情图片
175 UIImage *xw_image = [self getImageWithImageName:imageName bundleName:@"CNLiveMineModule" targetClass:[self class]]; 176 UIImage *xw_image = [self getImageWithImageName:imageName bundleName:@"CNLiveMineModule" targetClass:[self class]];
176 attch.image = xw_image; 177 attch.image = xw_image;
177 - UIFont *fonts = UIFontCNMake(font);  
178 178
  179 + CGFloat paddingTop = font.lineHeight - font.pointSize;
179 if(isFront){ 180 if(isFront){
180 // 设置图片大小 181 // 设置图片大小
181 - CGFloat paddingTop = fonts.lineHeight - fonts.pointSize;  
182 - attch.bounds = CGRectMake(0, -paddingTop, fonts.pointSize*5/6.0, fonts.pointSize); 182 + attch.bounds = CGRectMake(0, -paddingTop, font.pointSize*5/6.0, font.pointSize);
183 // 创建带有图片的富文本 183 // 创建带有图片的富文本
184 NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; 184 NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch];
185 [attri insertAttributedString:str atIndex:0];// 插入某个位置 185 [attri insertAttributedString:str atIndex:0];// 插入某个位置
186 }else{ 186 }else{
187 // 设置图片大小 187 // 设置图片大小
188 - CGFloat paddingTop = fonts.lineHeight - fonts.pointSize;  
189 - attch.bounds = CGRectMake(10, -paddingTop, fonts.pointSize, fonts.pointSize); 188 + attch.bounds = CGRectMake(10, -paddingTop, font.pointSize, font.pointSize);
190 // 创建带有图片的富文本 189 // 创建带有图片的富文本
191 NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; 190 NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch];
192 [attri insertAttributedString:str atIndex:string.length];// 插入某个位置 191 [attri insertAttributedString:str atIndex:string.length];// 插入某个位置
@@ -196,17 +195,6 @@ static const NSInteger margin = 20; @@ -196,17 +195,6 @@ static const NSInteger margin = 20;
196 195
197 } 196 }
198 197
199 -- (NSMutableAttributedString *)getAttributedString:(NSString *)content image:(UIImage *)image font:(UIFont *)font {  
200 - NSMutableAttributedString *contentAtt = [[NSMutableAttributedString alloc] initWithString:content attributes:@{NSFontAttributeName : font}];  
201 - NSTextAttachment *imageMent = [[NSTextAttachment alloc] init];  
202 - imageMent.image = image;  
203 - CGFloat paddingTop = font.lineHeight - font.pointSize;  
204 - imageMent.bounds = CGRectMake(0, -paddingTop, font.lineHeight, font.lineHeight);  
205 - NSAttributedString *imageAtt = [NSAttributedString attributedStringWithAttachment:imageMent];  
206 - [contentAtt appendAttributedString:imageAtt];  
207 - return contentAtt;  
208 -}  
209 -  
210 - (NSMutableAttributedString *)createAttributedImages:(NSArray *)images { 198 - (NSMutableAttributedString *)createAttributedImages:(NSArray *)images {
211 // 1.创建一个富文本 199 // 1.创建一个富文本
212 NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@""]; 200 NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@""];
@@ -297,7 +285,7 @@ static const NSInteger margin = 20; @@ -297,7 +285,7 @@ static const NSInteger margin = 20;
297 _name.numberOfLines = 1; 285 _name.numberOfLines = 1;
298 _name.textColor = [UIColor whiteColor]; 286 _name.textColor = [UIColor whiteColor];
299 _name.font = [UIFont systemFontOfSize:16]; 287 _name.font = [UIFont systemFontOfSize:16];
300 - _name.attributedText = [self createAttributedImageName:@"mine_code" string:CNUserShareModel.nickname font:16.0 isFront:NO]; 288 + _name.attributedText = [self createAttributedImageName:@"mine_code" string:CNUserShareModel.nickname fontSize:16.0 isFront:NO];
301 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nameTapDidClicked:)]; 289 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nameTapDidClicked:)];
302 [_name addGestureRecognizer:tap]; 290 [_name addGestureRecognizer:tap];
303 291
@@ -320,7 +308,7 @@ static const NSInteger margin = 20; @@ -320,7 +308,7 @@ static const NSInteger margin = 20;
320 _address.numberOfLines = 1; 308 _address.numberOfLines = 1;
321 _address.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:142/255.0 alpha:1.0]; 309 _address.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:142/255.0 alpha:1.0];
322 _address.font = [UIFont systemFontOfSize:13]; 310 _address.font = [UIFont systemFontOfSize:13];
323 - _address.attributedText = [self createAttributedImageName:@"mine_location" string:CNUserShareModel.location font:13.0 isFront:YES]; 311 + _address.attributedText = [self createAttributedImageName:@"mine_location" string:CNUserShareModel.location fontSize:13.0 isFront:YES];
324 } 312 }
325 return _address; 313 return _address;
326 } 314 }