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 | 174 | // 表情图片 |
| 175 | 175 | UIImage *xw_image = [self getImageWithImageName:imageName bundleName:@"CNLiveMineModule" targetClass:[self class]]; |
| 176 | 176 | attch.image = xw_image; |
| 177 | + UIFont *fonts = UIFontCNMake(font); | |
| 178 | + | |
| 177 | 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 | 184 | NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; |
| 182 | 185 | [attri insertAttributedString:str atIndex:0];// 插入某个位置 |
| 183 | 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 | 191 | NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch]; |
| 188 | 192 | [attri insertAttributedString:str atIndex:string.length];// 插入某个位置 |
| ... | ... | @@ -191,6 +195,18 @@ static const NSInteger margin = 20; |
| 191 | 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 | 210 | - (NSMutableAttributedString *)createAttributedImages:(NSArray *)images { |
| 195 | 211 | // 1.创建一个富文本 |
| 196 | 212 | NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@""]; |
| ... | ... | @@ -284,7 +300,7 @@ static const NSInteger margin = 20; |
| 284 | 300 | _name.attributedText = [self createAttributedImageName:@"mine_code" string:CNUserShareModel.nickname font:16.0 isFront:NO]; |
| 285 | 301 | UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nameTapDidClicked:)]; |
| 286 | 302 | [_name addGestureRecognizer:tap]; |
| 287 | - | |
| 303 | + | |
| 288 | 304 | } |
| 289 | 305 | return _name; |
| 290 | 306 | } | ... | ... |