來來來 先上來一個封裝的富文本函數(shù)吧,集成了圖片文本色下劃線等等
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px 'PingFang SC'; color: #1d9421}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #6122ae}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1d9421}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; min-height: 21.0px}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3d1d81}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #6122ae}span.s3 {font: 18.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #000000}span.s4 {font: 18.0px Menlo; font-variant-ligatures: no-common-ligatures}span.s5 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s6 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s7 {font: 18.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures}span.s8 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s9 {font-variant-ligatures: no-common-ligatures; color: #0435ff}span.s10 {font-variant-ligatures: no-common-ligatures; color: #c32275}
-
(NSAttributedString *)attrbutedString:(NSString *)text withImage:(UIImage *)image
{
// 創(chuàng)建可變屬性字符串羞福,富文本
NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] init];
// 將UIImage轉換為Attachement
NSTextAttachment * attachment = [[NSTextAttachment alloc] init];
attachment.image = image;// 將Attachement轉變?yōu)楦晃谋?br> NSAttributedString * attachementAttr = [NSAttributedString attributedStringWithAttachment:attachment];
// 將text轉變?yōu)楦晃谋?br> NSAttributedString * textAttr = [[NSAttributedString alloc] initWithString:text attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]}];
// 拼接
[attrString appendAttributedString:attachementAttr];
[attrString appendAttributedString:textAttr];return [attrString copy];
}
使用的時候注意哦p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #703daa}
Lable.attributedText = attStr;