IOS-common skills, ios-skills

Source: Internet
Author: User

IOS-common skills, ios-skills
Tip 1:

When writing programs, we cannot write Fixed Screen width and height, for example, 320,480, because we need to adapt to different mobile phones. One common method is to set the width and height in the. pch file, because. pch is a pre-compiled file and can be accessed globally.

# Define ScreenHeight [UIScreen mainScreen]. bounds. size. hight;

# Define ScreenWidth [UIScreen mainScreen]. bounds. size. width;

Tip 2:

This problem is simple and not a skill at all, but sometimes we ignore this usage. Set the background image for UIView.

_ TabbarView. backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @ "tabbar_background.png"];

Tip 3:

Our image is square and we want it to be displayed on the interface in a circular or elliptical shape.

_ Image = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0, 80, 80)];

_ Image. layer. cornerRadius = 40; // different sizes and different shapes

_ Image. clipsToBounds = YES;

Tip 4:

How to obtain the main window.

UIApplication * app = [UIApplication multicast application];

1. UIWindow * window = app. keyWindow;

2, UIWindow * window = app. delegate. window;

3. UIWindow * window = [app. windows objectAtIndex: 0];

Of course, we can also use the write method: for example: UIWindow * window = [UIApplication using application]. delegate. window;

Tip 5:

Sometimes we accidentally modify the system API or some other operations. What should we do if the following problems occur?

Error message: fatal error: file/Application ..........

Note: after modifying system headers, please delete the module cache at/Users .....

Solution: Go to/Users .... In this folder, delete the files and then clean the program.

Tip 5:

How to pause and start a timer is not enabled or disabled.

NSTimer * timer = [nst1_sch…];

[Timer setFireDate: [NSDate distantFuture]; // pause

[Timer setFireDate: [NSDate distantPass] // start

Tip 6:

The pop-up keyboard is usually a letter keyboard.

Textfiled. keyboardType = UIKeyboardTypeNumberPad;

Tip 7:

In a network request, if the request body contains Chinese characters, the request will fail. How can this problem be solved?

Assume that the request body is: NSString * urlString = @ "http://v.juhe.cn/weather/index? Cityname = Beijing ";

A request error occurs because it contains Chinese characters. Solution:

UrlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];

Tip 8:

How to enlarge images without deformation.

_ Image = [[UIImage imageNamed: @ "a.png"] stretchableImageWithLeftCapWidth: 20 topCapHeight: 10];

 

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.