Chapter I.
1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 5 @end6 7 @implementationViewcontroller8 9 Ten-(Ibaction) buttonpressed: (UIButton *) Sender { One //Remove the title of the button ANSString *title =[Sender Titleforstate:uicontrolstatenormal]; - - //use the removed title format as a string and assign a value to the new NSString object theNSString *plaintext = [NSString stringWithFormat:@"pressing%@ button", title]; - - //_statuslabel.text = plaintext; //assigns a formatted string to the label's Text property - + //variable string attribute class, creating object -Nsmutableattributedstring *textstyle =[[nsmutableattributedstring alloc]initwithstring:plaintext]; + A //nsdictionary dictionary new Syntax @{} is used to save string properties: Nsarray array new syntax is @[] atNsdictionary *dict = - @{ - Nsfontattributename:[uifont Boldsystemfontofsize:_statuslabel.font.pointsize] - }; - - //remove the substring to be changed in the plaintext string that is the title can also use @ "" to remove other strings inNsrange Namerange =[plaintext Rangeofstring:title]; - to //sets the string property. + [TextStyle setattributes:dict range:namerange]; - the_statuslabel.attributedtext =TextStyle; * $ Panax Notoginseng } - @end
Proficient in iOS Development Sixth Edition, Chapter One, examples and exercises in the article.