1) prior to iOS 7 there was also a technique for text typesetting and rendering--core text, and the introduction of text kit was not intended to replace the Core text. The Core text is a face???? Layer of text typesetting and rendering techniques, if we need to be text content?? ??, Best from a performance perspective when rendering to a graphics context? Scheme?? is using core Text.?? Is it from easy?? Using the text kit as a??, is the best choice, because?? Can straight???? Use some text controls provided by Uikit, such as Uitextview, Uilabel, and Uitextfield, to format the text.
The text kit has a number of advantages: Literal controls Uitextview, Uitextfield, and Uilabel are built on top of the text kit. Text kit complete?? Control the text layout and rendering: You can adjust the kerning??、 line?? Distance, text size??, specified?? Text to be paginated or column-,?? Support?? Text editing??、 customization?? Word cut?? Broken?? Line wrapping 、?? Support text Folded?? and coloring?? and other processing,?? Support convex?? Printing efficiency?????? Fruit.
?? 2) When we use the text kit, what happens? The following core classes are involved.
3) readers like?????? Read the illustrations?? The article, so in the application interface, sometimes not?? Just?? Need to have text, but also have pictures, this involves???? And a mix of text and pictures. In the process of mixed graphics and text will inevitably involve?? and text???? Picture of the situation, a lot of word processing?? (such as Word, WPS, Open Office, etc.)?? have this function. Text Kit by???????? (Exclusion paths) The text according to the specified?? Path?????? Around a view object, such as a picture.
The introduction of mixed text is basically the case, the following directly on the way!
*.h file
@property (Nonatomic,strong) Nstextcontainer *textcontainer; @property (Strong, nonatomic) iboutlet Uitextview * TextView; @property (weak, nonatomic) Iboutlet uiimageview *imageview;/** * Find keywords Modify colors and styles * @param word keywords * @param textstor Age Nstextstorage Object */-(void) Markword: (NSString *) word intextstorage: (nstextstorage *) textstorage;
*.M file
-(void) viewdidload {[Super viewdidload]; Do any additional setup after loading the view from its nib. Create a rectangular area CGRect textviewrect=cgrectinset (self.view.bounds, 10.0, 20.0); Create the Nstextstorage object, which requires a string as a constructor parameter, here we are out of the TextView control to pay its value to the Nstextstorage *textstorage=[[nstextstorage Alloc] InitWithString:self.textView.text]; Nslayoutmanager *layoutmanager=[[nslayoutmanager alloc] init]; Associate the Nstextstorage and Nslayoutmanager objects that you just created [Textstorage Addlayoutmanager:layoutmanager]; Self.textcontainer =[[nstextcontainer alloc] initWithSize:textViewRect.size]; Linking Nslayoutmanager and Nstextcontainer [LayoutManager AddTextContainer:self.textContainer]; /** * Rebuild the original TextView control and add it back to the view. This is mainly because the code can only be re-created * to be managed by Nslayoutmanager in the text kit, and the TextView control originally created in Interface Builder does not use */[Self.textview Remo Vefromsuperview]; Self.textview=[[uitextview Alloc] Initwithframe:textviewrect textcontainer:_textcontainer];//[Self.view AddSubview : SelF.textview]; [Self.textview Setfont:[uifont systemfontofsize:20.0f]; Added TextView under ImageView [Self.view InsertSubview:self.textView BelowSubview:self.imageView]; setting letterpress effect [Textstorage beginediting]; /** * Declares a Dictionary object, which includes @{nstexteffectattribute-*name:nstexteffectletterpressstyle},nstexteffectattributename is a text effect built, and *nstexteffect-letterpressstyle are text effect values, which are all constants */nsdictionary *attrsdic = @{nstexteffectattributename:nstexteffe Ctletterpressstyle}; nsmutableattributedstring *attrstr = [[nsmutableattributedstring alloc] Initwithstring:_textview.text attributes: Attrsdic]; [Textstorage SETATTRIBUTEDSTRING:ATTRSTR]; [Self markword:@ "I" intextstorage:textstorage]; [Self markword:@ "N" intextstorage:textstorage]; [Textstorage endediting]; [Email protected] [[Self translatedbezierpath]];//Set Translatedbezierpath method}//change coordinates of TextView and ImageView-(Uibezierpath *) translatedbezierpath{cgrect imagerect = [Self.textview convertrect:_imageview. Frame FromView:self.view]; Uibezierpath *newpath = [Uibezierpath bezierpathwithrect:imagerect]; return NewPath;} Sets style style based on specified text-(void) Markword: (NSString *) word intextstorage: (nstextstorage *) textstorage{//Nsregularexpression * Regex=[nsregularexpression Regularexpressionwithpattern:word options:0 Error:nil]; The text content in TextView is scanned with the regular Expression Nsregularexpression object, and the result is placed in the array Nsarray *matches=[regex matchesinstring: Self.textView.text options:0 range:nsmakerange (0, [self.textView.text length])]; Sets the color for the found text for (Nstextcheckingresult *match in matches) {Nsrange Matchrange=[match Range]; [Textstorage addattribute:nsforegroundcolorattributename Value:[uicolor Redcolor] range:matchRange]; }}
Then the effect of the picture and text mix can be completed by the above code.
4) previous iOS users complained about????, why can't I set a custom?? Font???? It? In iOS 7 system?? After the Apple for the font on the display do?? A number of optimization,?? Make different size?? The fonts on the screen are all?? To be clear???? To display. Usually the user set their own bias?? Good font, the user can???? (set?? -"General-" auxiliary???? Help function) settings?? The process of bold text. The user can also display the???? (set?? -"universal"?? -"Text Size"??) is the text size set?? The process.
?? However, it is not set in the settings???? What's the matter?? , we also need to program in the application code to deal with these changes. We need to set the text control to the user-set font in the app, not in the code?? encoding font and size??。 IOS 7 can be uifont in the new?? Increased Preferredfontfortextstyle: How to do?? User-set font.
6 font styles are available for selection in IOS 7.
?? Uifonttextstyleheadline. Title font, for example: newspaper?? The title.
?? Uifonttextstylesubheadline. Sub-heading font.
?? Uifonttextstylebody. The body font.
?? Uifonttextstylefootnote.?? Footnote font.
?? UIFontTextStyleCaption1. Title font, General?? For photos or subtitles.??
UIFontTextStyleCaption2. Another optional caption font
Monitoring system Settings [[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector ( Preferredcontentsizechanged:) name:uicontentsizecategorydidchangenotification Object:nil];
Set Font Size-(void) preferredcontentsizechanged: (nsnotification *) notification{ Self.textview.font=[uifont Preferredfontfortextstyle:uifonttextstylebody];}
After these two steps, you can set up a dynamic font!!!!!
IOS Graphics Mix