NSMutableAttributedString设置图片与文本的垂直位置
2017-01-08 11:04
471 查看
- (void)setZiValue:(NSInteger)zhi {
NSDictionary *attributeDict = [NSDictionary
dictionaryWithObjectsAndKeys:
[UIFont
fontByName:nil
fontSize:28.f],NSFontAttributeName,
[UIColor
colorWithNumber:MCOLOR],NSForegroundColorAttributeName,nil];
NSMutableAttributedString *string = [[NSMutableAttributedString
alloc]
initWithString:[NSString
stringWithFormat:@"%ld ",(long)zhi]
attributes:attributeDict];
[string addAttributes:@{NSBaselineOffsetAttributeName:@(8)}
range:(NSRange){0,string.length}];
NSInteger length = string.length;
NSTextAttachment *textAttachment = [[NSTextAttachment
alloc] initWithData:nil
ofType:nil];
textAttachment.image = [UIImage
imageWithContentsOfFile:[DeviceInfo
AppBaseResourcePath:@"DS_zi_icon@3x.png"]];
NSAttributedString *textAttachmentString = [NSAttributedString
attributedStringWithAttachment:textAttachment];
[string insertAttributedString:textAttachmentString
atIndex:string.length];
[string addAttributes:@{NSBaselineOffsetAttributeName:@(4)}
range:(NSRange){length,textAttachmentString.string.length}];
_priceLabel.attributedText = string;
}
NSDictionary *attributeDict = [NSDictionary
dictionaryWithObjectsAndKeys:
[UIFont
fontByName:nil
fontSize:28.f],NSFontAttributeName,
[UIColor
colorWithNumber:MCOLOR],NSForegroundColorAttributeName,nil];
NSMutableAttributedString *string = [[NSMutableAttributedString
alloc]
initWithString:[NSString
stringWithFormat:@"%ld ",(long)zhi]
attributes:attributeDict];
[string addAttributes:@{NSBaselineOffsetAttributeName:@(8)}
range:(NSRange){0,string.length}];
NSInteger length = string.length;
NSTextAttachment *textAttachment = [[NSTextAttachment
alloc] initWithData:nil
ofType:nil];
textAttachment.image = [UIImage
imageWithContentsOfFile:[DeviceInfo
AppBaseResourcePath:@"DS_zi_icon@3x.png"]];
NSAttributedString *textAttachmentString = [NSAttributedString
attributedStringWithAttachment:textAttachment];
[string insertAttributedString:textAttachmentString
atIndex:string.length];
[string addAttributes:@{NSBaselineOffsetAttributeName:@(4)}
range:(NSRange){length,textAttachmentString.string.length}];
_priceLabel.attributedText = string;
}
相关文章推荐
- 富文本NSMutableAttributedString的相关设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- iphone开发中NSMutableAttributedString/NSAttributedString 富文本设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- IOS NSMutableAttributedString 富文本的设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- NSMutableAttributedString/NSAttributedString 富文本设置
- iOS开发富文本制作 图片和文字/NSMutableParagraphStyle/NSMutableAttributedString
- NSMutableAttributedString文本样式设置以及富文本展示
- iOS使用NSMutableAttributedString实现富文本
- NSMutableAttributedString 设置不同颜色,不同字体的String
- NSMutableAttributedString 文本样式 (一)
- UILabel设置多种字体、颜色 (NSMutableAttributedString)
- 富文本 ---- NSMutableAttributedString
- NSMutableAttributedString 富文本框 设置下划线
- iOS使用NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)
- iOS使用NSMutableAttributedString 实现富文本(不同颜色字体、下划线等)
- IOS开发-NSMutableAttributedString 富文本的使用