17: Return to the main thread for operation, update the UI only on the main thread
/* display the data to the UI control, note that the UI can only be updated in the main thread, and the Performselectoronmainthread method is the NSObject classification method, each NSObject object has this method, The selector method that it calls is the method that is currently calling the control, such as when using Uiimageview call Selector is the method of Uiimageview Object: The argument that represents the calling method, but only one argument is passed ( If there are multiple parameters, use the object for encapsulation)*/[self performselectoronmainthread: @selector (updateimage:) Withobject: Data Waituntildone:yes];
18: Summary of Uiimageview usage
//InitializeUiimageview *imageview=[[uiimageview Alloc] Initwithframe:cgrectmake ( -, $, -, -)];//need to set the picture UIImage (the first type with the second will cache to memory, consume memory, but later access has the advantage when only loading once recommended with a third type)The first type: [ImageView setimage:[uiimage imagenamed:@"1.jpeg"]];//The second type:NSString *filepath=[[nsbundle Mainbundle] Pathforresource:@"1"OfType:@"JPEG"]; UIImage*images=[UIImage Imagewithcontentsoffile:filepath];//[ImageView setimage:images];//The third type:NSData *data=[NSData Datawithcontentsoffile:filepath]; UIImage*image2=[UIImage Imagewithdata:data]; [ImageView Setimage:image2];
19: Get child controls by tag
The first thing to do is to add a tag to the property of this child control, UIButton* button=[UIButton Buttonwithtype:uibuttontypecustom]; Button.tag= -; Button.frame=cgrectmake ( the,310, -, -); [Button addtarget:self action: @selector (play:) forcontrolevents:uicontroleventtouchupinside]; [Button setimage:[uiimage imagenamed:@"Play.png"] Forstate:uicontrolstatenormal]; [Self.view Addsubview:button], and then can be obtained through Viewwithtag, Self.view is this view, is the parent view of the button UIButton* button = (uibutton*) [Self.view Viewwithtag: -];
20: Background image of dynamic modifier keys
with one parameter, play:, you can do it this way//Play buttonuibutton* button=[UIButton Buttonwithtype:uibuttontypecustom]; Button.tag= -; Button.frame=cgrectmake ( the,310, -, -); [Button addtarget:self action: @selector (play:) forcontrolevents:uicontroleventtouchupinside]; [Button setimage:[uiimage imagenamed:@"Play.png"] Forstate:uicontrolstatenormal]; [Self.view Addsubview:button];//Play-(void) Play: (uibutton*) button{if(_audioplayer.playing) {[Button setimage:[uiimage imagenamed:@"Play.png"] Forstate:uicontrolstatenormal]; [_audioplayer pause]; } Else{[Button setimage:[uiimage imagenamed:@"Stop.png"] Forstate:uicontrolstatenormal]; [_audioplayer play]; } }
21: Determine if the simulator is not
-(void =@ " Determine if it is a simulator " ; [Self issimulator];} -(void ) issimulator{ if (Target_iphone_simulator) {NSLog ( @ " is a simulator " ); else @ " not a simulator "
22:16 Colors into Uicolor
- (void) viewdidload{[Super Viewdidload]; //Do any additional setup after loading the view.UIView*view=[[uiview Alloc]initwithframe:cgrectmake ( -, -, $, $)]; View.backgroundcolor=[self colorwithhexstring:@"e26562"]; [Self.view Addsubview:view]; }//16 binary color #e26562 and Uicolor, set view background color-(Uicolor *) colorwithhexstring: (NSString *) color{NSString*cstring =[[Color Stringbytrimmingcharactersinset:[nscharacterset Whitespaceandnewlinecharacterset]] uppercaseString]; //String should be 6 or 8 characters if([cString Length] <6) { return[Uicolor Clearcolor]; } //strip 0X If it appears if([cString Hasprefix:@"0X"]) cString= [CString Substringfromindex:2]; if([cString Hasprefix:@"#"]) cString= [CString Substringfromindex:1]; if([cString length]! =6) return[Uicolor Clearcolor]; //separate into R, G, b substringsNsrange Range; Range.location=0; Range.length=2; //RNSString *rstring =[cString Substringwithrange:range]; //gRange.location =2; NSString*gstring =[cString Substringwithrange:range]; //bRange.location =4; NSString*bstring =[cString Substringwithrange:range]; //Scan ValuesUnsignedintR, G, B; [[Nsscanner scannerwithstring:rstring] Scanhexint:&R]; [[Nsscanner scannerwithstring:gstring] Scanhexint:&G]; [[Nsscanner scannerwithstring:bstring] Scanhexint:&b]; return[Uicolor colorwithred: ((float) R/255.0f) Green: ((float) G/255.0f) Blue: ((float) b/255.0f) Alpha:1.0f];}
iOS Development Basics-Fragmentation 4