ios-Common Skills

Source: Internet
Author: User

Tip One:

When we write the program, the width of the screen is not fixed, such as writing 320,480, because we want to adapt to different mobile phones. One common way is to set the width height in the. pch file, because the. pch is a precompiled file that can be accessed globally.

#define ScreenHeight [UIScreen mainscreen].bounds.size.hight;

#define ScreenWidth [UIScreen mainscreen].bounds.size.width;

Tip Two:

This is a simple question, not a skill at all, but sometimes we ignore this usage. is to set the background image for UIView.

_tabbarview.backgroundcolor = [Uicolor colorwithpatternimage:[uiimage imagenamed:@ "Tabbar_background.png"];

Tip Three:

Our picture is square, and we want it to appear in the interface with a shape like a circle or an ellipse.

_image = [[Uiimageview alloc]initwithframe:cgrectmake (0,0,80,80)];

_image.layer.cornerradius = 40;//different sizes, different shapes

_image.clipstobounds = YES;

Tip Four:

Three ways to get the main window.

UIApplication *app=[uiapplication Shareapplication];

1,uiwindow *window = App.keywindow;

2,uiwindow *window = App.delegate.window;

3,uiwindow *window = [App.windows objectatindex:0];

Of course we can also use ligatures method: For example: UIWindow *window = [UIApplication Shareapplication].delegate.window;

Tip Five:

We sometimes accidentally modify the system's API, or some other operations, the following problems arise?

Error message: Fatal error:file/application ....

Note:after Modifying system headers, please delete the module cache at/users .....

Workaround: Go to/users. This folder, delete the files inside, and then clean the program can be resolved.

Tip Five:

How do we make the timer pause and start, not turn on and off.

Nstimer *timer = [Nstimer sch ...];

[Timer setfiredate: [NSDate distantfuture]];//Pause

[Timer setfiredate: [NSDate distantpass]]//start

Tip Six:

The keyboard that we pop up is usually the letter keyboard, how to eject the numeric keypad.

Textfiled.keyboardtype = Uikeyboardtypenumberpad;

Tip Seven:

In the network request, if the request body has Chinese characters, the request will be wrong, how to solve?

Suppose the request body is: NSString *urlstring= @ "Http://v.juhe.cn/weather/index?cityname= Beijing";

Because there are kanji characters, the request will go wrong. Treatment methods:

URLString = [URLString stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];

Tip Eight:

How to make our picture enlarged without distortion.

_image = [[UIImage imagenamed:@ "A.png"]stretchableimagewithleftcapwidth:20 topcapheight:10];

ios-Common Skills

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.