Key syntax for Coretext
One, coordinate rotation
-(void) DrawRect: (cgrect) rect{//Get ContextCgcontextref CTX =Uigraphicsgetcurrentcontext (); //in context, create a standard coordinate systemCgcontextsettextmatrix (CTX, cgaffinetransformidentity); //The origin in the context is moved in parallel, and the following is moved along the y-axis, transforming it into a screen coordinate system .CGCONTEXTTRANSLATECTM (CTX,0, Self.bounds.size.height); //Flip Y-Axis squareCGCONTEXTSCALECTM (CTX,1.0, -1.0); //Draw the dimension (Stringmodel is a string model, which is calculated in advance to draw the dimension), directly to drawCtframeref Ctframe =Self.stringModel.ctFrame; Ctframedraw (Ctframe, CTX);}
Second, the main key name
//1, set font properties, default: Font: Helvetica (Neue) font size:Nsfontattributename//2, set the font color, the value is Uicolor object, the default value is blackNsforegroundcolorattributename//3, set the font area background color, the value is Uicolor object, the default value is nil, transparent colorNsbackgroundcolorattributename//4, set the conjoined property, the value is NSNumber object (integer), 0 means no conjoined characters, 1 means to use the default conjoined charactersNsligatureattributename//5, set the character spacing, the value is NSNumber object (integer), positive spacing widened, negative spacing narrowingNskernattributename//6, set strikethrough, value is NSNumber object (integer)Nsstrikethroughstyleattributename//7. Set strikethrough color, value is Uicolor object, default value is blackNsstrikethroughcolorattributename//8, set underline, value is NSNumber object (integer), enumeration constant Nsunderlinestyle value, similar to strikethroughNsunderlinestyleattributename//9, set the underline color, the value is Uicolor object, the default value is blackNsunderlinecolorattributename//10, set the stroke width, the value is NSNumber object (integer), negative fill effect, positive effect of the hollowNsstrokewidthattributename//11, fill part color, not font color, value is Uicolor objectNsstrokecolorattributename//12, set the Shadow property, the value is Nsshadow objectNsshadowattributename//13, set the text special effect, the value is NSString object, at present only the plate printing effect is availableNstexteffectattributename//14, set the baseline offset value, the value is NSNumber (float), positive bias, negative biasNsbaselineoffsetattributename//15, set the glyph inclination, the value is NSNumber (float), positive right, negative left-leaningNsobliquenessattributename//16. Set text transverse stretch property, value NSNumber (float), positive values stretch text horizontally, negative values compress text horizontallyNsexpansionattributename//17. Set the direction of writing, write from left to right or write from right to leftNswritingdirectionattributename//18, set the text layout direction, the value is NSNumber object (integer), 0 for horizontal text, 1 for vertical textNsverticalglyphformattributename//19, set the link properties, click on the browser to open the specified URL addressNslinkattributename//20, set the text attachment, the value is Nstextattachment object, commonly used in the text picture mixed rowNsattachmentattributename//21, set the text paragraph layout format, the value is Nsparagraphstyle objectNsparagraphstyleattributename
Three, the main function
//1. Pass in the Ctframe and return an array containing multiple Ctline objects. cfarrayref ctframegetlines (ctframeref frame) ct_available (10_5, 3_2);//2. Get the number of elements in the arraycfindex Cfarraygetcount (cfarrayref thearray);//3. Get the element of IDX in the arrayConst void*Cfarraygetvalueatindex (cfarrayref thearray, Cfindex idx);//4. Get the base origin of all ctlineref, pass in Ctframe,cfrange, and a cgpoint array pointer, which writes each ctline's origin coordinates to the array. voidCtframegetlineorigins (ctframeref frame, Cfrange range, Cgpoint origins[]) ct_available (10_5, 3_2);//5. Get the range of text in Ctline in the whole paragraphcfrange Ctlinegetstringrange (ctlineref line) ct_available (10_5, 3_2);//6. Get an array of Ctrun in Ctlinecfarrayref Ctlinegetglyphruns (ctlineref line) ct_available (10_5, 3_2);//7. Get the range of Ctrun in the entire textCfrange Ctrungetstringrange (ctrunref Run) ct_available (10_5, 3_2);//8. Get the index of the position text in the whole paragraph at the Clickcfindex ctlinegetstringindexforposition (ctlineref line, cgpoint position) ct_available (10_5, 3_2);//9. Gets the x value of the character of the charindex position in the whole paragraph relative to the origin of lineCGFloat Ctlinegetoffsetforstringindex (ctlineref line,cfindex charindex,cgfloat *__nullable Secondaryoffset) Ct_available (10_5, 3_2);//10. Get the number of glyphs in the arraycfindex Ctlinegetglyphcount (ctlineref line) ct_available (10_5, 3_2);//11. Set the coordinates before the coretext is drawn. Set the baseline locationCg_externvoidcgcontextsettextposition (Cgcontextref __nullable C, CGFloat x, cgfloat y) cg_available_starting (__MAC_10_0, __I PHONE_2_0); //12, Draw ctline. voidCtlinedraw (ctlineref line, Cgcontextref context) ct_available (10_5, 3_2);//13. Get the upstream height of ctline, downlink height, line spacingDoubleCtlinegettypographicbounds (ctlineref line, CGFloat*__nullable Ascent, CGFloat*__nullable descent, CGFloat*__nullable leading) Ct_available (10_5, 3_2); //14. Set the current text matrixCg_externvoidCgcontextsettextmatrix (Cgcontextref __nullable C, Cgaffinetransform t) cg_available_starting (__MAC_10_0, __ IPHONE_2_0); //15, get a line of text range, that is, this line of text points have a pixel matrix as an image image, to the entire rectangular region. Offsets and widths relative to the origin of each line's baseline (for example: {{1.2,-2.57227}, {208.025, 19.2523}}, offset 1.2 units to the right, offset by 2.57227 units, followed by the width height)cgrect Ctlinegetimagebounds (ctlineref line, cgcontextref __nullable context) ct_available (10_5, 3_2);
Common syntax for Ios:coretext