iOS Development-oc Learning-common function code snippet collation

Source: Internet
Author: User

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

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.