1. Get the global delegate object so that we can invoke the methods and variables in this object:
- [(myappdelegate*) [[UIApplication Sharedapplication] delegate] mymethodormyvariable];
2. Get the main bundle of the program:
- NSBundle *bundle = [NSBundle mainbundle];
Bundles can be understood as a folder in which the content follows a specific framework.
One of the main uses of the main bundle is the use of resource files, slices, sounds, plst files, etc. in the program.
- Nsurl *plisturl = [bundle urlforresource:@"Plistfile" withextension:@ "plist"];
The above code obtains the path to the Plistfile.plist file.
3. Play the Sound in the program:
First add Audiotoolbox to the program:
Next, add #import in the. M method that has the play sound method:
- #import <AudioToolbox/AudioToolbox.h>
Next, the code to play the sound is as follows:
- NSString *path = [[NSBundle mainbundle] pathforresource:@"soundfilename" oftype:@"wav"];
- Systemsoundid Soundid;
- Audioservicescreatesystemsoundid (__bridge cfurlref) [Nsurl Fileurlwithpath:path], &soundid);
- Audioservicesplaysystemsound (Soundid);
4. Set and get property values in the class:
- [Self setValue: Variable value forkey: variable name];
- [Self valueforkey: variable name];
5. Let a method execute after a certain period of time in the future:
- [Self Performselector: @selector (method name) Withobject:nil Afterdelay: Delay time (s)];
6. Get the device version number:
- float Version = [[[Uidevice Currentdevice] systemversion] floatvalue];
7, the capture program closed or into the background event:
- UIApplication *app = [UIApplication sharedapplication];
- [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (applicationwillresignactive:) Name: Uiapplicationwillresignactivenotification Object:app];
Applicationwillresignactive: Add the desired action in this method
8. Check the fonts supported by the device:
- For (NSString *family in [Uifont Familynames]) {
- NSLog (@"%@", family);
- For (NSString *font in [Uifont fontnamesforfamilyname:family]) {
- NSLog (@"\t%@", font);
- }
- }
9. Add a click event for Uiimageview:
- imageview.userinteractionenabled = YES;
- UITapGestureRecognizer *singletap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector ( Yourhandlingcode:)];
- [ImageView Addgesturerecognizer:singletap];
10. Add multi-language support:
For example, a component such as Image picker, the text of the button above is changed as the device language environment changes, but first the language is added to the project:
11, enable the program to support devices such as itunes, such as the use of PC-side tools to the program documents to drag and drop files:
12, the page switch effect settings:
- Controller.modaltransitionstyle = uimodaltransitionstylecoververtical;
- [Self Presentmodalviewcontroller:controller animated:yes];
The effects available for use:
- Uimodaltransitionstylecoververtical//New view appears from bottom up
- Uimodaltransitionstylefliphorizontal//With the device's long axis as the center of the rollover appears
- Uimodaltransitionstylecrossdissolve//Gradually show
- Uimodaltransitionstylepartialcurl//Original view roll up
To restore the previous page:
- [Self dismissmodalviewcontrolleranimated:yes];
13. Get the screenshot
- -(UIImage *) Getscreenshot {
- Uigraphicsbeginimagecontext (self.view.bounds.size);
- [Self.view.layer Renderincontext:uigraphicsgetcurrentcontext ()];
- UIImage *image = Uigraphicsgetimagefromcurrentimagecontext ();
- Uigraphicsendimagecontext ();
- return image;
- }
iOS Development tips build up