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
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"];
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.