iOS Development-oc Learning-common function code snippet collation
Some code snippets are frequently used in iOS development to implement some fixed functionality. For example, after typing in the text box to get the keyboard back, this need to use a simple text box to lose the first responder's identity to complete. Or if you're doing URL-related functionality, you need to add a piece of code to the Info.plist to enable the URL to complete the conversion from HTTP to HTTPS, among other things.
In the process from a novice to the gradual learning of various functions, codes, controls, methods, but also gradually accumulate some knowledge, but at one time will not remember these things deeply and fully understood. So record these things here to remind yourself that you have to spend more time in the knowledge that you've learned before.
To get to the top, here's a list of common code snippets that are summed up:
First, how to let the virtual keyboard after the completion of the input back.
Second, how to convert HTTP URLs to HTTPS.
Third, how to get the screen resolution to complete the different resolution of the device's UI layout automatic adaptation.
Detailed code for each feature in the above directory:
first, how to let the virtual keyboard after the completion of the input recovery:
1 // when you're done, click the blanks in the input box to make the keyboard disappear 2 -(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *)event {3// password for text input control 4 [Password Resignfirstresponder]; 5 }
Ii. how to convert HTTP URLs to https:
1 <key>NSAppTransportSecurity</key>2 <dict>3 <key> Nsallowsarbitraryloads</key>4 <true/>5 </dict>
Note that the above code snippet is used as: right-info.plist the file and use source code to open it, then insert the above 5 lines of code after a random key-value pair.
Third, how to get the screen resolution to complete the different resolution device UI layout automatically adapt:
1 //Screen Size2CGRect rect =[[UIScreen mainscreen] bounds];3Cgsize size =rect.size;4CGFloat width =Size.width;5CGFloat height =Size.Height;6NSLog (@"Print%f,%f", width,height);7 8 //resolution9CGFloat Scale_screen =[UIScreen Mainscreen].scale;TenWidth*scale_screen,height*scale_screen
iOS Development-oc Learning-common function code snippet collation