IOS富文本文字属性

一、设置字体属性(NSFontAttributeName)

NSMutableAttributedString  *textFont = [[NSMutableAttributedString  alloc] initWithString:@"NSAttributedString设置字体大小"];

[textFont  addAttribute:NSFontAttributeName

value:[UIFont  boldSystemFontOfSize:18.0]

range:[@"NSAttributedString设置字体大小"rangeOfString:@"NSAttributedString"]];

二、设置文本段落排版格式(NSParagraphStyleAttributeName)

NSMutableParagraphStyle  *rowParagraph = [[NSMutableParagraphStyle  alloc] init];

rowParagraph.firstLineHeadIndent =20;

rowParagraph.lineSpacing =10;

NSMutableAttributedString*textRowSpace = [[NSMutableAttributedString  alloc] initWithString:@"NSAttributedString设置字体文字间距"];

[textRowSpace addAttribute:NSParagraphStyleAttributeName

                    value:rowParagraph

range:NSMakeRange(0, textRowSpace.string.length)];

三、设置字体颜色(NSForegroundColorAttributeName)

NSMutableAttributedString  *textColor = [[NSMutableAttributedString  alloc] initWithString:@"NSAttributedString设置字体颜色"];

[textColor addAttribute:NSForegroundColorAttributeName

value:[UIColor  greenColor]

range:[@"NSAttributedString设置字体颜色"rangeOfString:@"NSAttributedString"]];

四、设置字体所在区域背景颜色(NSBackgroundColorAttributeName)

NSMutableAttributedString  *textBackColor = [[NSMutableAttributedString  alloc] initWithString:@"NSAttributedString设置字体背景颜色"];

[textBackColor addAttribute:NSBackgroundColorAttributeName

value:[UIColor  yellowColor]

range:[@"NSAttributedString设置字体背景颜色"rangeOfString:@"NSAttributedString"]];

五、设置字符间距(NSKernAttributeName)

NSMutableAttributedString  *textSizeSpace = [[NSMutableAttributedString  alloc] initWithString:@"NSAttributedString设置字体文字间距"];

[textSizeSpace addAttribute:NSKernAttributeName

value:@(2)

range:[@"NSAttributedString设置字体文字间距"  rangeOfString:@"NSAttributedString"]];

六、设置删除线(NSStrikethroughStyleAttributeName)

NSMutableAttributedString  *text = [[NSMutableAttributedString  alloc] initWithString:@"NSAttributedString设置删除线"];

[text addAttribute:NSStrikethroughStyleAttributeName

value:@(NSUnderlineStyleSingle)

range:[@"NSAttributedString设置删除线"rangeOfString:@"NSAttributedString"]];

七、设置删除线颜色(NSStrikethroughColorAttributeName)

NSMutableAttributedString  *text = [[NSMutableAttributedString  alloc] initWithString:@"NSAttributedString设置删除线"];

[text addAttribute:NSStrikethroughColorAttributeName

value:[UIColor  blueColor]

range:[@"NSAttributedString设置删除线"rangeOfString:@"NSAttributedString"]];

你可能感兴趣的:(IOS富文本文字属性)