1. Property name
1> NSFontAttributeName (Font)
The value corresponding to this property is a UIFont object.This property is used to change the font of a piece of text.If this property is not specified, it defaults to 12-point Helvetica(Neue).
2> NSParagraph StyleAttributeName (Paragraph)
The value corresponding to this property is a NSParagraphStyle object.This attribute applies multiple attributes to a single piece of text.If you do not specify this property,
Default is the default paragraph property returned by the defaultParagraphStyle method of NSParagraphStyle.
3> NSForegroundColorAttributeName (font color)
The value corresponding to this property is a UIColor object.This property is used to specify the font color of a piece of text.If this property is not specified, it defaults to black.
4> NSBackgroundColorAttributeName (Font Background Color)
The value corresponding to this property is a UIColor object.This property is used to specify the background color of a piece of text.If this property is not specified, no background color is defaulted.
5> NSLigatureAttributeName (hyphen)
The value corresponding to this property is a NSNumber object (integer).Hyphenated characters refer to certain characters that are hyphenated together.
They use a single meta-symbol.0 means there are no hyphens.1 indicates that the default hyphenation character is used.2 means to use all the conjoined symbols.The default value is 1 (note that iOS does not support a value of 2).
6> NSKernAttributeName
The value corresponding to this property is a NSNumber object (integer).Alphabetical alignment specifies the number of pixels used to adjust the kerning.The effect of tight letters depends on the font.A value of 0 means no tight alphabets are used.The default value is 0.
7> NSStrikethrough StyleAttributeName (Strikeout)
The value corresponding to this property is a NSNumber object (integer).The value specifies whether to add a strikethrough to the text, which refers to Underline Style Attributes.The default value is NSUnderlineStyleNone.
8> NSUnderlineStyleAttributeName
The value corresponding to this property is a NSNumber object (integer).The value specifies whether to underline the text, which refers to Underline Style Attributes.The default value is NSUnderlineStyleNone.
9> NSStrokeColorAttributeName
The value corresponding to this property is a UIColor object.If this property is not specified (default), it is equivalent to NSForegroundColorAttributeName.
Otherwise, specify the color of the strikethrough or underscore.
10> NSStrokeWidthAttributeName (Edge Width)
The value corresponding to this property is a NSNumber object (decimal).This value changes the stroke width (as a percentage of the font size).Default is 0, that is, unchanged.Positive numbers only change the stroke width.
Negative numbers change both the description edge and fill width of the text.For example, for common hollow words, this value is usually 3.0.
11> NSShadowAttributeName (Shadow)
The value corresponding to this property is a NSShadow object.The default is nil.
12> NSVerticalGlyphFormAttributeName (horizontal and vertical typesetting)
The value corresponding to this property is a NSNumber object (integer).0 means horizontal text.1 stands for vertical text.In iOS, horizontal text is always used, and values other than 0 are undefined.
2. Code Effects
3. Code
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"NSAttributeString Can be used to set font, paragraph style, font color, font background color, can add strikethroughs, underscores, can set word spacing, shadows, hollow words, italics, flattening"];
- [attributedString addAttribute:NSExpansionAttributeName value:@1 range:NSMakeRange(0, 17)]; //Flattening
- [attributedString addAttribute:NSObliquenessAttributeName value:@1 range:NSMakeRange(18, 8)];//Tilt
- //Paragraph
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- paragraphStyle.firstLineHeadIndent = 80; //First line indentation
- paragraphStyle.headIndent = 25; //Other line indentation
- paragraphStyle.lineSpacing = 10; //Row spacing
- [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attributedString.length)];//Paragraph
- NSShadow *shadow = [[NSShadow alloc] init];
- shadow.shadowBlurRadius = 5; //Fuzziness
- shadow.shadowColor = [UIColor yellowColor];
- shadow.shadowOffset = CGSizeMake(1, 3);
- [attributedString addAttribute:NSVerticalGlyphFormAttributeName value:@(0) range:NSMakeRange(27, 4)];
- [attributedString addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(27, 4)];
- [attributedString addAttribute:NSStrokeWidthAttributeName value:@(-3.0) range:NSMakeRange(32, 11)];//Edge Line Width
- [attributedString addAttribute:NSStrokeColorAttributeName value:[UIColor greenColor] range:NSMakeRange(32, 11)];//Side Line Color, Side Line Width needs to be set first
- [attributedString addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(44, 7)]; //Delete line
- [attributedString addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(52, 3)]; //Underline
- [attributedString setAttributes:@{
- NSFontAttributeName:[UIFont fontWithName:@"Arial-BoldItalicMT" size:18], //Font, Size
- NSKernAttributeName:@(10), //Word spacing
- NSForegroundColorAttributeName:[UIColor blueColor],
- NSBackgroundColorAttributeName:[UIColor brownColor]
- }
- range:NSMakeRange(56, 20)];
- UILabel *label = [[UILabel alloc] initWithFrame:self.view.bounds];
- label.numberOfLines = 0;
- label.backgroundColor = [UIColor grayColor];
- label.attributedText = attributedString;
- [self.view addSubview:label];
- }
- @end