Commit 866a6e725ca1b36db82f84869dbaaa9ee09e9efd
1 parent
939d145e
no message
Showing
1 changed file
with
12 additions
and
24 deletions
CNLiveMineModule/Classes/View/CNLiveMineHeaderView.m
| ... | ... | @@ -52,10 +52,10 @@ static const NSInteger margin = 20; |
| 52 | 52 | [_header sd_setImageWithURL:[NSURL URLWithString:info] placeholderImage:xw_image]; |
| 53 | 53 | |
| 54 | 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 | 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 | 143 | - (void)setIsRefresh:(BOOL)isRefresh{ |
| 144 | 144 | _isRefresh = isRefresh; |
| 145 | 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 | 160 | } |
| 161 | 161 | */ |
| 162 | 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 | 164 | if(isFront){ |
| 165 | 165 | string = [NSString stringWithFormat:@" %@",string]; |
| 166 | 166 | } |
| ... | ... | @@ -168,25 +168,24 @@ static const NSInteger margin = 20; |
| 168 | 168 | NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:string]; |
| 169 | 169 | // 修改富文本中的不同文字的样式 |
| 170 | 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 | 173 | // 2.添加表情图片 |
| 173 | 174 | NSTextAttachment *attch = [[NSTextAttachment alloc] init]; |
| 174 | 175 | // 表情图片 |
| 175 | 176 | UIImage *xw_image = [self getImageWithImageName:imageName bundleName:@"CNLiveMineModule" targetClass:[self class]]; |
| 176 | 177 | attch.image = xw_image; |
| 177 | - UIFont *fonts = UIFontCNMake(font); | |
| 178 | 178 | |
| 179 | + CGFloat paddingTop = font.lineHeight - font.pointSize; | |
| 179 | 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 | 184 | NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; |
| 185 | 185 | [attri insertAttributedString:str atIndex:0];// 插入某个位置 |
| 186 | 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 | 190 | NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; |
| 192 | 191 | [attri insertAttributedString:str atIndex:string.length];// 插入某个位置 |
| ... | ... | @@ -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 | 198 | - (NSMutableAttributedString *)createAttributedImages:(NSArray *)images { |
| 211 | 199 | // 1.创建一个富文本 |
| 212 | 200 | NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@""]; |
| ... | ... | @@ -297,7 +285,7 @@ static const NSInteger margin = 20; |
| 297 | 285 | _name.numberOfLines = 1; |
| 298 | 286 | _name.textColor = [UIColor whiteColor]; |
| 299 | 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 | 289 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nameTapDidClicked:)]; |
| 302 | 290 | [_name addGestureRecognizer:tap]; |
| 303 | 291 | |
| ... | ... | @@ -320,7 +308,7 @@ static const NSInteger margin = 20; |
| 320 | 308 | _address.numberOfLines = 1; |
| 321 | 309 | _address.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:142/255.0 alpha:1.0]; |
| 322 | 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 | 313 | return _address; |
| 326 | 314 | } | ... | ... |