iOS Development Basics-Fragmentation 4

Source: Internet
Author: User

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

Related Article

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.