Commit 939d145ef6732630e86b292fdc58d9513bc29855
1 parent
30dc6ef8
no message
Showing
1 changed file
with
19 additions
and
3 deletions
CNLiveMineModule/Classes/View/CNLiveMineHeaderView.m
| @@ -174,15 +174,19 @@ static const NSInteger margin = 20; | @@ -174,15 +174,19 @@ static const NSInteger margin = 20; | ||
| 174 | // 表情图片 | 174 | // 表情图片 |
| 175 | UIImage *xw_image = [self getImageWithImageName:imageName bundleName:@"CNLiveMineModule" targetClass:[self class]]; | 175 | UIImage *xw_image = [self getImageWithImageName:imageName bundleName:@"CNLiveMineModule" targetClass:[self class]]; |
| 176 | attch.image = xw_image; | 176 | attch.image = xw_image; |
| 177 | + UIFont *fonts = UIFontCNMake(font); | ||
| 178 | + | ||
| 177 | if(isFront){ | 179 | if(isFront){ |
| 178 | // 设置图片大小 | 180 | // 设置图片大小 |
| 179 | - attch.bounds = CGRectMake(0, -2, 10, 12); | 181 | + CGFloat paddingTop = fonts.lineHeight - fonts.pointSize; |
| 182 | + attch.bounds = CGRectMake(0, -paddingTop, fonts.pointSize*5/6.0, fonts.pointSize); | ||
| 180 | // 创建带有图片的富文本 | 183 | // 创建带有图片的富文本 |
| 181 | NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; | 184 | NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; |
| 182 | [attri insertAttributedString:str atIndex:0];// 插入某个位置 | 185 | [attri insertAttributedString:str atIndex:0];// 插入某个位置 |
| 183 | }else{ | 186 | }else{ |
| 184 | // 设置图片大小 | 187 | // 设置图片大小 |
| 185 | - attch.bounds = CGRectMake(10, -2, 15, 15); | 188 | + CGFloat paddingTop = fonts.lineHeight - fonts.pointSize; |
| 189 | + attch.bounds = CGRectMake(10, -paddingTop, fonts.pointSize, fonts.pointSize); | ||
| 186 | // 创建带有图片的富文本 | 190 | // 创建带有图片的富文本 |
| 187 | NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; | 191 | NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; |
| 188 | [attri insertAttributedString:str atIndex:string.length];// 插入某个位置 | 192 | [attri insertAttributedString:str atIndex:string.length];// 插入某个位置 |
| @@ -191,6 +195,18 @@ static const NSInteger margin = 20; | @@ -191,6 +195,18 @@ static const NSInteger margin = 20; | ||
| 191 | return attri; | 195 | return attri; |
| 192 | 196 | ||
| 193 | } | 197 | } |
| 198 | + | ||
| 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 | + | ||
| 194 | - (NSMutableAttributedString *)createAttributedImages:(NSArray *)images { | 210 | - (NSMutableAttributedString *)createAttributedImages:(NSArray *)images { |
| 195 | // 1.创建一个富文本 | 211 | // 1.创建一个富文本 |
| 196 | NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@""]; | 212 | NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@""]; |
| @@ -284,7 +300,7 @@ static const NSInteger margin = 20; | @@ -284,7 +300,7 @@ static const NSInteger margin = 20; | ||
| 284 | _name.attributedText = [self createAttributedImageName:@"mine_code" string:CNUserShareModel.nickname font:16.0 isFront:NO]; | 300 | _name.attributedText = [self createAttributedImageName:@"mine_code" string:CNUserShareModel.nickname font:16.0 isFront:NO]; |
| 285 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nameTapDidClicked:)]; | 301 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nameTapDidClicked:)]; |
| 286 | [_name addGestureRecognizer:tap]; | 302 | [_name addGestureRecognizer:tap]; |
| 287 | - | 303 | + |
| 288 | } | 304 | } |
| 289 | return _name; | 305 | return _name; |
| 290 | } | 306 | } |