UIImage two different types of initialization ad carousel encapsulation

Source: Internet
Author: User

UIImage Two types of initialization differences

The first type of initialization: UIImage *image = [UIImage imagenamed:@ "xxx"]; Note (This method loads the picture if the suffix name is png, you can not write the suffix name, according to the screen resolution to match the picture yourself)

The second type of initialization:

NSString *path = [[NSBundle mainbundle] pathforresource:@ "Xxx.png" oftype:nil];
UIImage *image = [[UIImage alloc] initwithcontentsoffile:path]; Note (This method must write the suffix name)

Difference: The first method loads the picture and then puts the picture in the cache, and the next time the image is loaded, it can be read directly from the cache. Advantages: Convenient and quick, only the first time when loading a little slow, then will soon. Cons: Waste memory when the image is only loaded once in the project (note that this memory will be released only when the project is closed)

The second way to load a picture is to read the picture according to the path each time, the second method is recommended when the picture in the project only needs to be loaded once.

It's nothing to do today. Encapsulates an ad carousel control, the call is very simple, the external call of the time 1. If it's a local image, you just need to send an array of image names.

2. If it is a network image only need to pass a URL array is good

3 lines of code are done. And it can be automatically carousel, every second of the carousel. The finger swipe does not clash with the timer. Attached address: Https://github.com/guhaibo312/HBScrollView

UIImage two different types of initialization ad carousel encapsulation

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.