06-image browser, 06-Browser

Source: Internet
Author: User

06-image browser, 06-Browser
Introduction to the image browser Case Study

  • Next we will use UIImageView, UILabel, and UIButton to implement a comprehensive case study.
  • Function Analysis

  • Step Analysis

Master
  • Change the image of UIImageView
  • Measure the test taker's understanding about the contentMode of UIImageView.
  • Change the text of UILabel and set the automatic line break and text center of UILabel in storyboard.
  • Simple use of NSArray and NSDictionary
  • Create and read Plist files
  • Attribute lazy loading
  • Use of viewDidLoad Method
  • Multiple statuses of UIButton
Job
  • Use code-only method to rewrite the small case of the image browser (do not drag the control)
Basic UILabel settings
  • To make UILabel wrap automatically, set Lines to 0.
  • Center UILabel text

UIButton status
  • Normal)
  • Highlighted)
  • Disabled (invalid or unavailable)
  • If the enabled attribute is NO, it is in the disable state, indicating that the button cannot be clicked.
  • Corresponding enumerated constant: UIControlStateDisabled

UIButton and UIImageView
  • Similarities: images can be displayed
  • Differences
  • How to select
Use of NSArray and NSDictionary
  • When the image content is very large, the code "set content based on index" does not have scalability and needs to be changed frequently.
  • To change the status quo, you can consider saving the image data line to an array. There are many dictionaries in order in the array. One dictionary represents an image data, including the image name and description.

@ Property (strong, nonatomic) NSArray * images;

  • Because only image data needs to be initialized once, it is initialized in the get method.
  • The method for initializing attributes in the get method is called "lazy loading" \ "delayed loading"
What is a Plist file?
  • Writing data directly in the code is not a reasonable practice. If the data is frequently changed, the corresponding code should be frequently opened for modification, resulting in low code scalability.
  • Therefore, you can store frequently changed data in a file and read the latest data from the file after the program starts. To change the data, directly modify the data file without modifying the code.
  • Generally, you can use an attribute list file to store data such as NSArray or NSDictionary. The extension of this attribute list file is plist, which becomes a "Plist file"
Create a Plist File

Parse Plist files
  • Next, parse the data in the Plist file through code.

NSBundle * bundle = [NSBundle mainBundle]; NSString * path = [bundle pathForResource: @ "imageData" ofType: @ "plist"];

  • Load plist file _ images = [NSArray arrayWithContentsOfFile: path];

-(NSArray *) images

{

If (_ images = nil)

{

NSBundle * bundle = [NSBundle mainBundle];

NSString * path = [bundle pathForResource: @ "imageData" ofType: @ "plist"];

_ Images = [NSArray arrayWithContentsOfFile: path];

}

Return _ images;

}

 

Plist file parsing process

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.