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];