iOS nsmutableattributedstring detailed display of different fonts and colors of the string

Source: Internet
Author: User

1Nsmutableattributedstring *mutablestring =[[nsmutableattributedstring Alloc]initwithstring:totalfee];2 [mutablestring addattribute:nsfontattributename3Value:[uifont systemfontofsize:21.0]4Range:nsmakerange (3, Totalfee.length-3)];//Set Font5 [mutablestring addattribute:nsforegroundcolorattributename6 Value:[uicolor Redcolor]7Range:nsmakerange (3, Totalfee.length-3)];//Set Color8Sumlabel.attributedtext = mutablestring;

The initialization methods of nsattributedstring are:
-initwithstring: Initialized with string with no attributed information.
-initwithattributedstring: Initialize with attributedstring.
-initwithstring:attributed: Initialized with string and attribute dictionary.

The key value pairs for the specific attributtedstring property are as follows:
1, NSString *const nsfontattributename;//value is Uifont, set the font, the default value is 12-point Helvetica (Neue).
The following code allows you to see the fonts available in iOS, and to see the Font Book tool.

1Nsarray *familyarray =[Uifont familynames];2  for(IDFamilyinchFamilyarray) {3printf ("%s\n ", [family cstringusingencoding:nsutf8stringencoding]);4Nsarray *fontarray =[Uifont fontnamesforfamilyname:family];5      for(IDFontinchFontarray) {6printf ("%s\n ", [Font cstringusingencoding:nsutf8stringencoding]);7     }8}

2, NSString *const nsparagraphstyleattributename;//value is Nsparagraphstyle, set paragraph properties, the default value is [Nsparagraphstyle Defaultparagraphstyle] returns the value.
Nsmutableparagraphstyle and Nsparagraphstyle include the following properties:
Alignment//Alignment
Firstlineheadindent//First line Indent
Headindent//Indent
Tailindent//Trailing indent
Linebreakmode//Break method
Maximumlineheight//MAX row height
Minimumlineheight//Minimum row height
LineSpacing//Line spacing
Paragraphspacing//Segment Distance
Paragraphspacingbefore//Segment head space
Basewritingdirection//sentence direction
Lineheightmultiple//variable row height, multiply factor.
Hyphenationfactor//Hyphen Property
3, NSString *const nsforegroundcolorattributename;//value is uicolor, font color, default is black.
4, NSString *const nsbackgroundcolorattributename;//value is uicolor, font background color, the default is not.
5, NSString *const nsligatureattributename;//value for integer type NSNumber, hyphenation properties, general Chinese can not be used in English, may appear in the case of adjacent letters pen. 0 is not a pen, 1 is the default pen, and the default value, 2 is not supported on iOS.
6, NSString *const nskernattributename;//value is floating point number nsnumber, Kerning property, the default value is 0.
7, NSString *const nsstrikethroughstyleattributename;//value is integer nsnumber, the desired value is
enum {
Nsunderlinestylenone = 0x00,
Nsunderlinestylesingle = 0x01,
}; Set strikethrough.

8, NSString *const nsunderlinestyleattributename;//Ibid. Sets the underline.
9, NSString *const nsstrokecolorattributename;//value is Uicolor, the default value is nil, set the property with Foregroundcolor.
10, NSString *const nsstrokewidthattributename;//value is floating point number nsnumber. Sets the thickness of the drawing.
11, NSString *const nsshadowattributename;//value is Nsshadow, set the shadow of the picture, the default value is nil.
12, NSString *const nsverticalglyphformattributename;//value for the integer type nsnumber,0 for the horizontal layout of the word, 1 for vertical typesetting of the word.

iOS nsmutableattributedstring detailed display of different fonts and colors of the string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.