Images. xcassets, images. xcassets usage

Source: Internet
Author: User

Images. xcassets, images. xcassets usage
Overview of Images. xcassets

Allows you to conveniently manage image resources.

Image Acquisition Method
  • Image resources in Images. xcassets can only be loaded using imageNamed: method, and the path of the image cannot be obtained through pathForResource: ofType: Of NSBundle.
  • Therefore, Images. xcassets are only suitable for storing image resources that are commonly used by the system and occupy a small amount of memory.
AppIcon Example 1


-Display in finder


-Content. json

-Display on iPhone 6 s plus


-Display on iPhone 6

Modify the image set

Drag 60pt 2x Image


Summary
  • The number of pixels in each group indicates the image size when 1x is used (1x before iPhone4)
  • If the dragged image does not conform to the size, compilation fails. Crop an image of the corresponding size and drag it to the corresponding position on the interface.
  • From left to right, the image size is 120120,140140.
  • The dragged file name is displayed in content. json.
  • If 2x has a file of 60pt or 40 pt, the corresponding size of the image after scale is used in both spotlight and App icons ### example 2AppIcon
  • View in finder
  • IPhone6s
  • App icon on iPhone 6 p
  • Modify the AppIcon image set again.
    • If the image corresponding to 40pt 2x is added at this time, the previous app icon is displayed in spotlight.
    • Even if you delete the 60pt 2x image in xcode, the corresponding image name disappears in content. json. However, the App icon shown on iPhone 6 still looks like this.
  • Drag a new 60pt 2x image ### conclusion
  • If you only want to delete a group of 2x or 3x images. The previous image is still used for display.
  • After dragging a new image file, the new icon is displayed on the mobile phone without any changes.
  • If the spotlight image is not set at the beginning, the icon displayed on the spotlght will not be changed after the image is dragged into the later stage.
Create folders and image sets for user image resources
  • Create a New file using New Folder
    Clip

  • Create a New Image Set through the New Image Set
    Bytes

Drag the cropped Image

Bytes

Bytes

  • Code reference method
    • The name is the name of the image set.
    • Double-click iamge set to modify the image set name.
 self.header.image = [UIImage imageNamed:@"header"];    self.suit.image = [UIImage imageNamed:@"closing"];
  • Running Interface
Modify the displayed Image

You do not need to modify the code. You only need to drag the Image into the corresponding Image Set to renew.

Bytes

Summary
  • In this example, we can see the convenience of using xcassets to manage image resources: You can change the image and unordered code modification.
  • Images are well stored in xcasset, and a large number of chaotic image files are not displayed in the project.

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.