iOS development: Tips accumulate 2

Source: Internet
Author: User

Http://blog.sina.com.cn/s/articlelist_1935098904_1_1.html

, 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

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: such as image picker component, the text of the button above it changes with the device language environment, but first in the project to add language:

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

Uimodaltransitionstylefliphorizontal

Uimodaltransitionstylecrossdissolve

Uimodaltransitionstylepartialcurl

To restore the previous page:

[Self dismissmodalviewcontrolleranimated:yes];

iOS development: Tips accumulate 2

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.