Xcode Uiimageview creation, picture loading, audio file playback, deferred invocation

Source: Internet
Author: User

Code creation

/**

Create Uiimageview

*/

Uiimageview * Imageview=[[uiimageview Alloc]init];

/**

Set the size position

*/

Imageview.frame= (CGRect) {{50,50},{230,230}};

/**

Create a picture

*/

UIImage * Image=[[uiimage Alloc]init];

/**

Get Pictures

*/

Image=[uiimage imagenamed: @ "picture name"];

/**

Give the picture to the container

*/

imageview.image=image;

/**

< images with scale words may be stretched >

Uiviewcontentmodescaletofill

Stretch the picture to fill the entire ImageView

The picture shows the same size as the ImageView.

With scale words, with aspect words: may be stretched, but will maintain the image's original aspect ratio

Uiviewcontentmodescaleaspectfit

Guaranteed to just see all the pictures.

Uiviewcontentmodescaleaspectfill

Stretch to the width or height of the picture as ImageView

Words < images without scale will never be stretched, keeping the original width and height of the image

*/

Imageview.contentmode=uiviewcontentmodescaleaspectfit;

/**

The out-of-section is clipped

*/

imageview.clipstobounds=yes;

[Self.view Addsubview:imageview];

Picture loading

-No cache

NSString *file = [[NSBundle mainbundle] pathforresource: @ "picture name" oftype:@ "picture extension"];

UIImage *image = [UIImage imagewithcontentoffile:file];

* As long as the method name is file, all paths are passed

Use occasions: The picture is bigger, the use frequency is relatively low

Recommendation: Images that do not need to be cached cannot be placed in Images.xcassets

-There is a cache

UIImage *image =[uiimage imagenamed: @ "picture name"];

Use occasions: Pictures relatively small, the use of high frequency ratio

Recommendation: Place images that need to be cached in Images.xcassets

Audio file Playback

//Create a URL for an audio file (URL is the path object of the file)

Nsurl *url = [[NSBundle mainbundle] urlforresource: @ "audio filename" withextention:@ "audio file extension"];

--Another wording

Nsurl *url = [[NSBundle mainbundle] urlforresource: @ "audio file name extension" Withextention:nil ";

//Create player

Self.palyer = [Avplayer playerwithurl:url];

[Self.player play];

Deferred Call method

[OBJC performselector: @selector (stand:) withobject:@ "123" afterdelay:10];

After 10 seconds, call OBJC's stand: method, and pass the @ "123" parameter

Withobject can be any object

Xcode Uiimageview creation, picture loading, audio file playback, deferred invocation

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.