Skin resource management method and device applied to iOS system
By constructing a hierarchical architecture of the main project and multiple skin targets, and using a skin manager to uniformly manage the skin-changing process, the redundancy of resource management and configuration errors in traditional iOS skin-changing solutions are solved, improving development efficiency and user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HANGZHOU ROBAM APPLIANCES CO LTD
- Filing Date
- 2026-05-15
- Publication Date
- 2026-07-14
Smart Images

Figure CN122387571A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of mobile application development technology, and in particular to a method and apparatus for skin management in iOS systems. Background Technology
[0002] With the development of mobile internet, application personalization has become a core user need. Skinning functionality, as a crucial form of personalization, directly impacts development efficiency and user experience. Traditional iOS skinning solutions typically manage image resources by creating .bundle files in the main project to store skin images. However, .bundles cannot directly integrate .xcassets resource packages, requiring manual maintenance of images at different resolutions, leading to resource redundancy or missing elements and low development efficiency. Furthermore, color resource configuration usually uses a single JSON file to store color mappings; each new skin combination requires manually adding the corresponding values for all colors, resulting in redundant configuration and a high risk of errors. Summary of the Invention
[0003] The purpose of this invention is to provide a method and apparatus for skin-changing resource management in iOS systems. By pre-constructing a hierarchical architecture of the main project target and multiple skin targets, skin resources are stored independently of the main project, achieving physical isolation of resources. This allows adding new skins without modifying the main project structure, improving development efficiency. The skin-changing process is uniformly managed through a skin manager. Based on the target skin identifier, the current skin index is updated and the corresponding resource configuration is loaded. Then, by sending a skin-changing notification, all interface view controls are driven to reload resources through a unified resource refresh interface, achieving dynamic skin-changing of the entire interface without restarting the application, thus improving the user experience.
[0004] In a first aspect, the present invention provides a skin-changing resource management method applied to an iOS system, which pre-constructs a hierarchical architecture of a main project target and multiple skin targets; wherein, the main project target is used to store business logic and skin-changing control interfaces, and each skin target serves as an independent compilation unit to store all resources of the corresponding skin; the main project target calls resources in the skin targets through preset dependencies; the method includes: In response to the skin-changing event, the target skin identifier is obtained through the skin manager; the skin manager is a singleton object running in the main project target. The skin manager updates the current skin index to the index value corresponding to the target skin identifier based on the target skin identifier, and loads the image resource directory and color configuration file in the target skin corresponding to the target skin identifier; The skin manager sends skin notifications to all UI view controls that are listening for skin notifications. The UI view control responds to the skin change notification by reloading image and color resources from the target skin through a unified resource refresh interface, thus completing the skin change.
[0005] In some preferred embodiments of the present invention, each skin target is used as an independent compilation unit to store all resources of the corresponding skin, and the method further includes: Create a dedicated image resource directory for each skin target; the image resource directory is used to store all image resources for the skin. Assign the same image name to images that implement the same interface function in different skins, so that when the image is called by image name in the main project target, the actual image of the corresponding skin can be automatically obtained according to the currently loaded skin target; A color profile is stored in each skin target, and the color profile is used to define the color resources of the skin.
[0006] In some preferred embodiments of the present invention, the color configuration file is a static configuration file in JSON format; wherein, the static configuration file stores the mapping relationship between color identifiers and color values in the form of key-value pairs; During initialization, the skin manager loads static configuration files for all skin targets and constructs a three-dimensional mapping table containing skin identifiers, color identifiers, and color values. When switching to the target skin, the skin manager looks up the corresponding color value from the 3D mapping table and applies it based on the target skin identifier and the color identifier required by the interface view controls.
[0007] In some preferred embodiments of the present invention, the color profile is implemented through a dynamic runtime combination mode, and the method further includes: Define a color base class, which contains a unique color identifier property and a multi-skin color array property. Each element in the multi-skin color array corresponds to the color value of a skin. The index of the multi-skin color array is bound to the order of the skin types. During the initialization of the UI view control, a unique color identifier corresponding to the UI view control is bound to the UI view control through the associated object; The skin manager maintains a global index of the current skins and updates the index when a skin is switched. When a UI / UX control responds to a skinning notification, it matches and applies the target color value from the multi-skin color array of the color base class, based on the unique color identifier bound to the UI / UX control itself and the current skin index.
[0008] In some preferred embodiments of the present invention, the step of dynamically binding a unique color identifier corresponding to a UI view control to an associated object includes: In the classification of UI view controls, a new property for storing a unique color identifier is added to the UI view control based on the runtime associated object mechanism; When a UI / UX control is loaded from a layout file or created programmatically, its color unique identifier is read from the configuration, and the color unique identifier is bound to an instance of the UI / UX control through an associated object.
[0009] In some preferred embodiments of the present invention, the step of binding the index of the multi-skin color array with the skin type order includes: The first element of the multi-skin color array corresponds to the default skin, the second element corresponds to the dark skin, and the third element corresponds to the limited-edition holiday skin. When a new skin is added, the color value corresponding to the new skin is appended to the end of the multi-skin color array of all color base classes.
[0010] In some preferred embodiments of the present invention, the step of loading the image resource directory and color configuration file in the target skin corresponding to the target skin identifier includes: The skin manager determines the runtime package path of the corresponding target skin based on the target skin identifier; Load the image resource directory and color configuration file from the target skin via the package path so that subsequent resource access requests are redirected to the currently active target skin.
[0011] In some preferred embodiments of the present invention, the unified resource refresh interface is defined as the skin refresh process in the view control category; the step of reloading image resources and color resources from the target skin through the unified resource refresh interface includes: In the skin refresh process, the image loading process is called again to retrieve the image from the image resource directory of the current target skin, and the color retrieval process is called again to retrieve the color from the color configuration of the current target skin. Finally, the new resource is set to the property of the interface view control itself.
[0012] In some preferred embodiments of the present invention, the skin-changing event includes the user manually selecting a skin through the settings interface or the skin switching event automatically triggered by the application according to preset rules.
[0013] Secondly, this invention provides a skin-changing resource management device for iOS systems, which pre-constructs a hierarchical architecture of a main project target and multiple skin targets; wherein, the main project target is used to store business logic and skin-changing control interfaces, and each skin target serves as an independent compilation unit to store all resources of the corresponding skin; the main project target calls resources in the skin targets through preset dependency relationships; the device includes: The skin-changing response module is used to respond to the triggering of skin-changing events and obtain the target skin identifier through the skin manager; the skin manager is a singleton object running in the main project target; The configuration loading module is used by the skin manager to update the current skin index to the index value corresponding to the target skin identifier based on the target skin identifier, and load the image resource directory and color configuration file in the target skin corresponding to the target skin identifier; The skin notification module is used by the skin manager to send skin notifications to all UI view controls that are listening for skin notifications. The skin-changing execution module is used for UI view controls to respond to skin-changing notifications. It reloads image and color resources from the target skin through a unified resource refresh interface to complete the UI skin change.
[0014] This invention brings the following beneficial effects: This invention provides a method and apparatus for skin-changing resource management in an iOS system. It pre-constructs a hierarchical architecture of a main project target and multiple skin targets. The main project target stores business logic and skin-changing control interfaces, while each skin target serves as an independent compilation unit storing all resources for its corresponding skin. The main project target calls resources from the skin targets through pre-defined dependencies. The method includes: in response to a skin-changing event, obtaining a target skin identifier through a skin manager; wherein the skin manager is a singleton object running in the main project target; the skin manager updates the current skin index to the index value corresponding to the target skin identifier based on the target skin identifier, and loads the image resource directory and color configuration file from the target skin corresponding to the target skin identifier; skin changing... The skin manager sends skin-changing notifications to all UI / UX controls listening for them. In response, these controls reload image and color resources from the target skin via a unified resource refresh interface, completing the skin change. By pre-building a hierarchical architecture between the main project target and multiple skin targets, skin resources are stored independently of the main project, achieving physical resource isolation. This allows adding new skins without modifying the main project structure, improving development efficiency. The skin manager centrally manages the skin-changing process, updating the current skin index and loading the corresponding resource configuration based on the target skin identifier. Then, by sending skin-changing notifications, all UI / UX controls reload resources via the unified resource refresh interface, achieving dynamic skin changing for the entire interface without requiring an application restart, thus enhancing the user experience. Attached Figure Description
[0015] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0016] Figure 1 This is a schematic diagram of a skin-changing resource management logic architecture provided in an embodiment of the present invention; Figure 2 A flowchart illustrating a skin-changing resource management method applied to an iOS system, provided as an embodiment of the present invention; Figure 3 A flowchart illustrating the dynamic skin switching logic provided in this embodiment of the invention; Figure 4 This is a schematic diagram of a skin-changing resource management device applied to an iOS system, provided by an embodiment of the present invention. Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.
[0017] Icons: 310 - Skin-changing response module; 320 - Configuration loading module; 330 - Skin-changing notification module; 340 - Skin-changing execution module; 400 - Memory; 401 - Processor; 402 - Bus; 403 - Communication interface. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0019] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0020] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0021] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship commonly used when the product of this invention is in use. They are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this invention. In addition, the terms "first," "second," "third," etc., are only used to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0022] Furthermore, terms such as "horizontal," "vertical," and "sag" do not imply that components must be absolutely horizontal or suspended, but rather that they can be slightly tilted. For example, "horizontal" simply means that its direction is more horizontal relative to "vertical," and does not mean that the structure must be completely horizontal, but can be slightly tilted.
[0023] In the description of this invention, it should also be noted that, unless otherwise explicitly specified and limited, the terms "set," "install," "connect," and "link" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0024] The following detailed description of some embodiments of the present invention is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0025] Example 1 This invention provides a skin-changing resource management method for iOS systems, which pre-constructs a hierarchical architecture of a main project target and multiple skin targets. The main project target is used to store business logic and skin-changing control interfaces, and each skin target is used as an independent compilation unit to store all resources of the corresponding skin. The main project target calls resources in the skin targets through preset dependency relationships.
[0026] For details, see Figure 1The illustrated embodiment of the present invention provides a schematic diagram of a skin resource management logic architecture. In the Xcode development environment, the main project target is the main entry point of the application, containing all business logic code, view controllers, and skin control interfaces (such as the public methods of the SkinManager singleton). Each skin target is an independent compilation unit, generated through Xcode's Target creation function, and they are associated with the main project target through "target dependencies". In the project configuration, the "target dependencies" of the main project target are set to depend on all skin targets. Thus, when the main project compiles, it first compiles the skin targets and embeds the resource bundles generated by the skin targets into the main project's product bundle. Each skin target can independently manage its own resource files, including images, color configuration files, etc., without interfering with each other. This hierarchical architecture achieves physical isolation between skin resources and the main project code. When adding a new skin, only a new skin target needs to be added and dependencies configured; the main project does not need any modifications, thus supporting independent development, testing, and release of multiple skins. This architecture decouples skin resources from the main project, significantly shortens the development cycle of new skins, and greatly improves team collaboration efficiency.
[0027] Furthermore, in some preferred embodiments of the present invention, each skin target is used as an independent compilation unit to store all resources of the corresponding skin. The method further includes: creating a dedicated image resource directory in each skin target, the image resource directory being used to store all image resources of the skin; assigning the same image name to images that implement the same interface function in different skins, so that when the image is called by image name in the main project target, the actual image of the corresponding skin can be automatically obtained according to the currently loaded skin target; and storing a color configuration file in each skin target, the color configuration file being used to define the color resources of the skin.
[0028] Specifically, the image resource directory created in each skin target is in the .xcassets resource bundle format, which is standard for iOS development. During compilation, the .xcassets of each skin target are compiled into a corresponding Assets.car file and packaged into the dynamic resource bundle (.bundle) generated for that skin target. For example, the default skin target generates DefaultSkin.bundle after compilation, and the dark skin target generates DarkSkin.bundle. Each bundle contains its own Assets.car. To achieve automatic matching of image resources, developers set the exact same image name for images with the same interface function in different skins. For example, the image of the navigation bar back button is named btn_back_normal in the default skin and also named btn_back_normal in the dark skin, but the actual visual effect of the two images is different. In the main project code, when loading an image using [UIImage imageNamed:@"btn_back_normal"], the system will search for an image with the same name based on the Assets.car in the bundle corresponding to the currently active skin target, thus automatically returning the actual image for the correct skin. This mechanism fully leverages the automatic adaptation features of .xcassets, eliminating the need for manually concatenating skin prefixes or writing conditional judgment code. Therefore, the workload for maintaining image resources can be reduced by more than 50%, and resource redundancy or missing issues caused by manually managing multi-resolution images are avoided.
[0029] Furthermore, in some preferred embodiments of the present invention, the color configuration file is a static configuration file in JSON format; wherein, the static configuration file stores the mapping relationship between color identifiers and color values in the form of key-value pairs; the skin manager loads the static configuration files of all skin targets during initialization and constructs a three-dimensional mapping table containing skin identifiers, color identifiers, and color values; when switching to a target skin, the skin manager looks up the corresponding color value from the three-dimensional mapping table and applies it according to the target skin identifier and the color identifier required by the interface view control.
[0030] Specifically, in static JSON configuration mode, the contents of the colors.json file in each skin target are shown in the following example: { "text_primary": "#333333", "text_secondary": "#666666", "background_primary": "#FFFFFF", "background_secondary": "#F5F5F5"} When the application starts or the skin manager initializes, the skin manager iterates through all loaded skin targets, reads the colors.json file in each skin target bundle, parses its contents, and builds a three-dimensional mapping table in memory. The first dimension of this mapping table is the skin identifier (e.g., @"default", @"dark"), the second dimension is the color identifier (e.g., @"text_primary"), and the third dimension is the corresponding color value (e.g., a UIColor object). When the user switches to a target skin, the skin manager quickly locates the color mapping sub-table for that skin based on the target skin identifier; when a UI view control needs to set a color, only the color identifier (e.g., text_primary) needs to be provided, and the skin manager can find the corresponding color value from the current skin's color sub-table and return it. This static configuration method makes color configuration intuitive, easy to debug, and has extremely high query efficiency (hash table lookup), making it suitable for simple scenarios with fixed skin combinations, significantly reducing configuration costs and the probability of errors.
[0031] Furthermore, in some preferred embodiments of the present invention, the color configuration file is implemented through a dynamic runtime composition pattern. The method further includes: defining a color base class, which includes a color unique identifier attribute and a multi-skin color array attribute, wherein each element in the multi-skin color array corresponds to a color value of a skin; wherein the index of the multi-skin color array is bound to the skin type order; when the interface view control is initialized, the color unique identifier corresponding to the interface view control is bound to the interface view control through an associated object; the skin manager maintains the global current skin index and updates the current skin index when switching skins; the interface view control responds to the skin switching notification, and matches and applies the target color value from the multi-skin color array of the color base class according to the color unique identifier bound to the interface view control itself and the current skin index.
[0032] Specifically, the dynamic runtime composite pattern is a flexible solution for handling complex and ever-changing skin scenarios. First, define a base color class, such as `SkinColor`, which contains two properties: `colorKey` (a unique color identifier, such as `@"text_primary"`) and `values` (an array storing the color values for all skins in order). The array index is strictly bound to the skin type: by convention, index 0 represents the default skin, index 1 represents a dark skin, index 2 represents a holiday-limited skin, and so on. During the initialization of UI view controls (such as `UILabel` and `UIButton`) (e.g., in the `awakeFromNib` or `initWithFrame` methods), the `objc_setAssociatedObject` function dynamically binds the corresponding `colorKey` to the control instance. The binding process is usually implemented in the control's category, adding a `skinColorKey` property as the associated object. The skin manager (`SkinManager`) is a singleton, internally maintaining a global variable `currentSkinIndex` (the current skin index). When switching skins, the skin manager updates this index and sends a skin-switching notification. Upon receiving a notification, the UI view control retrieves the corresponding skin's color value from the globally maintained SkinColor object dictionary based on its bound colorKey and the currentSkinIndex, and applies it to the control's own color properties (such as textColor and backgroundColor). This pattern allows adding a new skin simply by appending the corresponding color value to the end of the array of all color base classes, without modifying any business logic, truly achieving flexible expansion with "zero code modification," and making the maintenance cost of color configuration close to zero.
[0033] Furthermore, in some preferred embodiments of the present invention, the step of dynamically binding the color unique identifier corresponding to the interface view control to the interface view control through the association object includes: adding an attribute to store the color unique identifier for the interface view control based on the runtime association object mechanism in the classification of interface view controls; when the interface view control is loaded from the layout file or created by code, reading the color unique identifier of the interface view control from the configuration, and binding the color unique identifier to the instance of the interface view control through the association object.
[0034] In implementation, a category is created for the UIView, such as UIView+Skin. Within this category, a `skinColorKey` string property is declared using `@property`, and its setter and getter methods are dynamically implemented using `objc_setAssociatedObject` and `objc_getAssociatedObject`. This gives all controls inheriting from UIView the ability to store color identifiers. For controls created via Storyboard or XIB layout files, the pre-set `skinColorKey` value can be read from user-defined runtime attributes in the `awakeFromNib` method. For controls created via code, a custom method (such as `setSkinColorKey:`) is called after initialization, passing in the color identifier. This implementation leverages iOS runtime features to dynamically add the ability to store color identifiers to existing control classes without modifying the control's native code. It offers good compatibility and low intrusion, while ensuring automatic binding and unbinding of color identifiers from the control's lifecycle.
[0035] Furthermore, in some preferred embodiments of the present invention, the step of binding the index of the multi-skin color array with the skin type order includes: the first element of the multi-skin color array corresponds to the default skin, the second element corresponds to the dark skin, and the third element corresponds to the holiday limited skin; when a new skin is added, the color value corresponding to the new skin is appended to the end of the multi-skin color array of all color base classes.
[0036] Specifically, this sequential binding mechanism ensures the stability and scalability of color mapping. For example, during application initialization, all necessary SkinColor objects are pre-created and populated in a fixed order in the values array: the default skin's color value is placed at index 0, the dark skin's color value at index 1, and the holiday skin's color value at index 2. When the application plans to add a new "Chinese New Year limited edition skin," the developer only needs to iterate through all SkinColor objects, append a new color value corresponding to the Chinese New Year skin to the end of each values array, and bind the type of the new skin to index 3. Since all color retrieval in the business code is done through "colorKey + current skin index," the new skin color corresponding to index 3 will be automatically applied. This mechanism greatly reduces the cost and risk of adding skins in subsequent versions, ensures the consistency and scalability of color mapping, and achieves true "define once, reuse multiple skins."
[0037] See Figure 2The flowchart shown in this embodiment of the invention provides a skin-changing resource management method applied to the iOS system and... Figure 3 The illustrated embodiment of the present invention provides a dynamic skin switching logic flowchart, the method comprising: Step S102: In response to the triggering of the skin-changing event, obtain the target skin identifier through the skin-changing manager; wherein, the skin-changing manager is a singleton object running in the main project target.
[0038] Specifically, the SkinManager uses a singleton pattern to ensure that there is only one skin management instance in the entire application. Its public interfaces include `+ (instancetype)sharedInstance` and `- (void)switchToSkinWithIdentifier:(NSString *)skinIdentifier`. Skin-changing events may originate from direct user actions, such as clicking the "Night Mode" button in the settings interface; or they may originate from internal application logic, such as automatically switching between day and night themes based on the system time. When an event occurs, the business layer calls the `switchToSkinWithIdentifier:` method, passing in the identifier string of the target skin (such as `@"dark"` or `@"festival"`). This method first performs some checks (such as whether the skin exists) and then triggers the subsequent skin-changing process. By uniformly managing the skin-changing entry point through a singleton, global consistency and controllable state of skin-changing operations are ensured, avoiding the state chaos caused by multiple instances.
[0039] Furthermore, in some preferred embodiments of the present invention, the skin-changing event includes the user manually selecting a skin through the settings interface or the skin switching event automatically triggered by the application according to preset rules.
[0040] Specifically, manual skin selection by the user is the most common triggering method. For example, in the application's "Themes & Skins" settings page, multiple options are provided for users to choose from. Automatic triggering is more intelligent: the application can register to listen for system time changes and automatically switch to dark mode in the evening; or automatically apply a holiday-limited skin when a specific holiday (such as Spring Festival or Mid-Autumn Festival) arrives, and revert to the default skin after the holiday ends. These automatic rules can be defined through a JSON file configured in the backend. The skin manager periodically checks whether the conditions are met, and if so, automatically calls the skin-changing interface. This multi-trigger design covers various skin-changing needs, respecting user choices while supporting intelligent automatic switching, thus improving the flexibility and satisfaction of the user experience.
[0041] In step S104, the skin manager updates the current skin index to the index value corresponding to the target skin identifier based on the target skin identifier, and loads the image resource directory and color configuration file in the target skin corresponding to the target skin identifier.
[0042] Specifically, the skin manager internally maintains a mapping dictionary from skin identifiers to skin indices, for example, `@{@"default": @0, @"dark": @1, @"festival": @2}`. Upon receiving a target skin identifier, it retrieves the corresponding index value from the dictionary and updates the global variable `currentSkinIndex`. Simultaneously, it finds the bundle path generated at runtime for the corresponding skin target based on the skin identifier. Since each skin target generates an independent `.bundle` file (e.g., `DarkSkin.bundle`) after compilation and is packaged into the main bundle of the main application, the skin manager can load this bundle using the `[NSBundlebundleWithPath:]` method. Once successfully loaded, this bundle becomes the currently active skin resource bundle, and all subsequent images loaded via `[UIImage imageNamed:]` and color values obtained through color configuration will be retrieved from this bundle. Through the coordinated updating of the index and resource bundle, the skin manager can quickly locate and activate the target skin, ensuring the accuracy and efficiency of subsequent resource access.
[0043] Furthermore, in some preferred embodiments of the present invention, the step of loading the image resource directory and color configuration file in the target skin corresponding to the target skin identifier includes: the skin manager determining the package path of the corresponding target skin at runtime based on the target skin identifier; loading the image resource directory and color configuration file in the target skin through the package path so that subsequent resource access requests are redirected to the currently active target skin.
[0044] Specifically, determining the bundle path can be achieved by pre-defining naming rules for skin bundles, such as including the skin identifier as part of the bundle name, like DefaultSkin.bundle and DarkSkin.bundle. After the skin manager obtains the bundle name, it retrieves the complete bundle path using the `pathForResource:ofType:` method of `[NSBundle mainBundle]`, and then loads the bundle using `[NSBundle bundleWithPath:]`. Once loaded, the bundle object can be saved as the `currentSkinBundle` property. For image loading, the `imageNamed:` method of `UIImage` can be extended to prioritize finding images in `currentSkinBundle`; for colors, the `colors.json` file can be read from the bundle and parsed into a color dictionary. This resource redirection mechanism seamlessly switches all resource requests to the new skin, requiring no additional checks in the developer's business logic, achieving zero intrusion into existing code.
[0045] Step S106: The skin manager sends a skin notification to all UI view controls that are listening for skin notifications.
[0046] Specifically, after completing index updates and resource loading, the skin manager sends a global notification via NSNotificationCenter, for example, named kSkinDidChangeNotification. All UI view controls that need to respond to skin changes should register to listen for this notification during initialization (e.g., in the init method or viewDidLoad) by calling `[[NSNotificationCenter defaultCenter] addObserver:selector:name:object:]`, and remove the listener in dealloc. The notification does not need to carry additional parameters because the information required by the control (current skin index, current resource package) can be obtained through the skin manager singleton. This notification mechanism decouples skin-changing events from UI updates; controls only need to focus on how they refresh, without needing to worry about the specific details of the skin-changing process, thus reducing coupling between modules.
[0047] In step S108, the interface view control responds to the skin change notification by reloading image and color resources from the target skin through a unified resource refresh interface, thus completing the interface skin change.
[0048] Specifically, when a control receives a `kSkinDidChangeNotification` notification, it calls a unified resource refresh method, such as `- (void)refreshSkin`. This method is implemented within the control's category and performs the following operations internally: For image properties (such as `image` in `UIImageView` and `backgroundImage` in `UIButton`), it calls the image loading method again to retrieve the image from the current skin bundle and resets it; for color properties (such as `textColor` in `UILabel` and `backgroundColor` in `UIView`), it retrieves the corresponding color value from `SkinManager` based on the control's bound `colorKey` and the current skin index and resets it. In this way, all UI elements will automatically update to the new skin style. The entire process does not require restarting the application, achieving a seamless skin-changing experience, and because the refresh interface is unified, it ensures the integrity and consistency of the interface update.
[0049] Furthermore, in some preferred embodiments of the present invention, the unified resource refresh interface is defined as the skin refresh process in the view control category; the step of reloading image resources and color resources from the target skin through the unified resource refresh interface includes: in the skin refresh process, re-invoking the image loading process to obtain images from the image resource directory of the current target skin, and re-invoking the color acquisition process to obtain colors from the color configuration of the current target skin, and finally setting the new resources to the properties of the interface view control itself.
[0050] Specifically, taking UIImageView as an example, its refreshSkin method is typically implemented as follows: First, it obtains the current skin bundle, then reloads the image using [UIImage imageNamed:originalImageName inBundle:currentSkinBundle compatibleWithTraitCollection:nil], and finally assigns the new image to self.image. For UILabel, its refreshSkin method calls [[SkinManager sharedInstance]colorForKey:colorKey] to obtain the color under the current skin based on the previously bound colorKey (e.g., @"text_primary"), and sets it to self.textColor. Internally, the color retrieval method extracts the color value from the values array of the corresponding SkinColor object based on the current skin index. This ensures that all UI controls can respond to skin changes in a unified way, resulting in high code reusability, low maintenance costs, and guaranteed accuracy and timeliness of the interface visuals after skin changes.
[0051] The skin resource management method for iOS system provided by this invention solves the technical pain point that .bundle cannot directly use .xcassets. By utilizing the automatic adaptation and compression features of .xcassets, the workload of image maintenance is reduced by more than 50%. The independent skin Target decouples resources from the main project, and shortens the development cycle of adding new skins by 60%.
[0052] The skin management method for iOS systems provided by this invention features a dual-mode design that covers both fixed and flexible scenarios. Static JSON reduces the configuration cost for simple scenarios, while dynamic runtime combinations reduce the amount of code changes required to add new skins to near zero. A unified color coding and indexing mechanism avoids code redundancy caused by hard coding and improves maintainability.
[0053] The skin-changing resource management method for iOS provided by this invention features a modular architecture that supports the independent development, testing, and release of skin resources, adapting to team collaboration scenarios. The standardized resource naming rules and interfaces enhance the reusability of the skin-changing function and allow for rapid portability to other projects.
[0054] This invention provides a skin-changing resource management method for iOS systems, which pre-constructs a hierarchical architecture of a main project target and multiple skin targets. The main project target stores business logic and skin-changing control interfaces, while each skin target serves as an independent compilation unit to store all resources for its corresponding skin. The main project target calls resources from the skin targets through pre-defined dependencies. The method includes: in response to a skin-changing event, obtaining the target skin identifier through a skin manager; wherein the skin manager is a singleton object running in the main project target; the skin manager updates the current skin index to the index value corresponding to the target skin identifier based on the target skin identifier, and loads the image resource directory and color configuration file from the target skin corresponding to the target skin identifier; the skin manager... The processor sends skin-changing notifications to all UI / UX controls listening for these notifications. In response, the UI / UX controls reload image and color resources from the target skin via a unified resource refresh interface, completing the skin change. By pre-building a hierarchical architecture between the main project target and multiple skin targets, skin resources are stored independently of the main project, achieving physical resource isolation. This allows adding new skins without modifying the main project structure, improving development efficiency. The skin-changing process is uniformly managed by the skin manager. Based on the target skin identifier, the current skin index is updated and the corresponding resource configuration is loaded. Then, by sending skin-changing notifications, all UI / UX controls are driven to reload resources via the unified resource refresh interface, achieving dynamic skin changing of the entire interface without requiring an application restart, thus improving the user experience.
[0055] Example 2 Based on the above embodiments, this invention provides a skin-changing resource management device for iOS systems, which pre-constructs a hierarchical architecture of a main project target and multiple skin targets; wherein, the main project target is used to store business logic and skin-changing control interfaces, and each skin target serves as an independent compilation unit to store all resources of the corresponding skin; the main project target calls resources in the skin targets through preset dependency relationships; see also Figure 4 The diagram shown is a structural schematic of a skin management device for an iOS system provided by an embodiment of the present invention. The device includes: The skin-changing response module 310 is used to respond to the triggering of skin-changing events and obtain the target skin identifier through the skin manager; wherein, the skin manager is a singleton object running in the main project target.
[0056] The configuration loading module 320 is used by the skin manager to update the current skin index to the index value corresponding to the target skin identifier based on the target skin identifier, and to load the image resource directory and color configuration file in the target skin corresponding to the target skin identifier.
[0057] The skin notification module 330 is used by the skin manager to send skin notifications to all UI view controls that are listening for skin notifications.
[0058] The skin-changing execution module 340 is used for the interface view control to respond to the skin-changing notification, and reload image resources and color resources from the target skin through a unified resource refresh interface to complete the interface skin-changing.
[0059] Furthermore, in some preferred embodiments of the present invention, each skin target is used as an independent compilation unit to store all resources of the corresponding skin. The device is also used to create a dedicated image resource directory in each skin target, which is used to store all image resources of the skin; to assign the same image name to images that implement the same interface function in different skins, so that when the image is called by image name in the main project target, the actual image of the corresponding skin can be automatically obtained according to the currently loaded skin target; and to store a color configuration file in each skin target, which is used to define the color resources of the skin.
[0060] Furthermore, in some preferred embodiments of the present invention, the color configuration file is a static configuration file in JSON format; wherein, the static configuration file stores the mapping relationship between color identifiers and color values in the form of key-value pairs; the skin manager loads the static configuration files of all skin targets during initialization and constructs a three-dimensional mapping table containing skin identifiers, color identifiers, and color values; when switching to a target skin, the skin manager looks up the corresponding color value from the three-dimensional mapping table and applies it according to the target skin identifier and the color identifier required by the interface view control.
[0061] Furthermore, in some preferred embodiments of the present invention, the color configuration file is implemented through a dynamic runtime composition pattern. The device is also used to define a color base class, which includes a color unique identifier attribute and a multi-skin color array attribute. Each element in the multi-skin color array corresponds to a color value of a skin. The index of the multi-skin color array is bound to the skin type order. When the interface view control is initialized, the color unique identifier corresponding to the interface view control is bound to the interface view control through an associated object. The skin manager maintains the global current skin index and updates the current skin index when switching skins. In response to the skin switching notification, the interface view control matches and applies the target color value from the multi-skin color array of the color base class according to the color unique identifier bound to the interface view control itself and the current skin index.
[0062] Furthermore, in some preferred embodiments of the present invention, the apparatus is also used to add a property for storing a unique color identifier to the interface view control based on the runtime association object mechanism in the classification of interface view controls; when the interface view control is loaded from the layout file or created by code, the unique color identifier of the interface view control is read from the configuration, and the unique color identifier is bound to the instance of the interface view control through the association object.
[0063] Furthermore, in some preferred embodiments of the present invention, the device is also used to make the first element of the multi-skin color array correspond to the default skin, the second element correspond to the dark skin, and the third element correspond to the holiday limited skin; when a new skin is added, the color value corresponding to the new skin is appended to the end of the multi-skin color array of all color base classes.
[0064] Furthermore, in some preferred embodiments of the present invention, a loading module 320 is configured to determine the package path of the corresponding target skin at runtime based on the target skin identifier; and load the image resource directory and color configuration file in the target skin through the package path so that subsequent resource access requests are redirected to the currently active target skin.
[0065] Furthermore, in some preferred embodiments of the present invention, the skin-changing execution module 340 is used to, in the skin refresh process, re-invoke the image loading process to obtain an image from the image resource directory of the current target skin, and re-invoke the color acquisition process to obtain a color from the color configuration of the current target skin, and finally set the new resource to the properties of the interface view control itself.
[0066] Furthermore, in some preferred embodiments of the present invention, the skin-changing event includes the user manually selecting a skin through the settings interface or the skin switching event automatically triggered by the application according to preset rules.
[0067] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the skin resource management device applied to the iOS system described above can be referred to the corresponding process in the aforementioned embodiments of the skin resource management method applied to the iOS system, and will not be repeated here.
[0068] Example 3 This invention also provides an electronic device for running a skinning resource management method applied to the iOS system; see [link to related documentation]. Figure 5 The schematic diagram of an electronic device provided by the embodiment of the present invention shown includes a memory 400 and a processor 401. The memory 400 is used to store one or more computer instructions, which are executed by the processor 401 to implement the skinning resource management method applied to the iOS system described above.
[0069] Furthermore, Figure 5 The electronic device shown also includes a bus 402 and a communication interface 403. The processor 401, the communication interface 403 and the memory 400 are connected via the bus 402.
[0070] The memory 400 may include high-speed random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 403 (which can be wired or wireless), such as the Internet, wide area network, local area network, metropolitan area network, etc. The bus 402 can be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0071] Processor 401 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 401 or by instructions in software form. Processor 401 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 400, and processor 401 reads information from memory 400 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments.
[0072] This invention also provides a computer-readable storage medium storing computer-executable instructions. When these computer-executable instructions are called and executed by a processor, they cause the processor to implement the above-described skinning resource management method applied to the iOS system. For specific implementation details, please refer to the method embodiments, which will not be repeated here.
[0073] The computer program product of the skinning resource management method, apparatus and electronic device for iOS system provided in the embodiments of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods in the preceding method embodiments. For specific implementation, please refer to the method embodiments, which will not be repeated here.
[0074] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and / or device described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0075] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.
[0076] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0077] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for skin-changing resource management applied to the iOS system, characterized in that, A hierarchical architecture of a main project target and multiple skin targets is pre-constructed; wherein, the main project target is used to store business logic and skin-changing control interfaces, and each skin target serves as an independent compilation unit to store all resources of the corresponding skin; the main project target calls resources in the skin targets through preset dependencies; the method includes: In response to the triggering of a skin-changing event, the target skin identifier is obtained through the skin manager; wherein, the skin manager is a singleton object running in the main project target; The skin manager updates the current skin index to the index value corresponding to the target skin identifier based on the target skin identifier, and loads the image resource directory and color configuration file in the target skin corresponding to the target skin identifier; The skin manager sends skin change notifications to all UI view controls that are listening for skin change notifications. The interface view control responds to the skin-changing notification by reloading image and color resources from the target skin through a unified resource refresh interface to complete the interface skin-changing.
2. The skinning resource management method applied to the iOS system according to claim 1, characterized in that, Each skin target serves as an independent compilation unit for storing all resources of the corresponding skin, and the method further includes: A dedicated image resource directory is created for each skin target, and the image resource directory is used to store all image resources of the skin; Assign the same image name to images that perform the same interface function in different skins, so that when the image is called by the image name in the main project target, the actual image of the corresponding skin can be automatically obtained according to the currently loaded skin target; A color profile is stored in each skin target, which is used to define the color resources of the skin.
3. The skinning resource management method applied to the iOS system according to claim 2, characterized in that, The color configuration file is a static configuration file in JSON format; wherein, the static configuration file stores the mapping relationship between color identifiers and color values in the form of key-value pairs; The skin manager loads static configuration files for all skin targets during initialization and constructs a three-dimensional mapping table containing skin identifiers, color identifiers, and color values. When switching to the target skin, the skin manager looks up the corresponding color value from the three-dimensional mapping table and applies it based on the target skin identifier and the color identifier required by the interface view control.
4. The skinning resource management method applied to the iOS system according to claim 2, characterized in that, The color configuration file is implemented through a dynamic runtime combination mode, and the method further includes: Define a color base class, which includes a unique color identifier attribute and a multi-skin color array attribute. Each element in the multi-skin color array corresponds to a color value for a skin. The index of the multi-skin color array is bound to the order of skin types. During the initialization of the interface view control, a unique color identifier corresponding to the interface view control is bound to the interface view control through an associated object; The skin manager maintains a global index of the current skin and updates the index when switching skins. In response to the skin-changing notification, the UI view control matches and applies the target color value from the multi-skin color array of the color base class based on the unique color identifier bound to the UI view control itself and the current skin index.
5. The skinning resource management method applied to the iOS system according to claim 4, characterized in that, The step of dynamically binding the unique color identifier corresponding to the UI view control to the associated object includes: In the classification of the interface view controls, a new attribute for storing a unique color identifier is added to the interface view controls based on the runtime associated object mechanism; When the UI view control is loaded from a layout file or created in code, its unique color identifier is read from the configuration, and the unique color identifier is bound to the instance of the UI view control through an association object.
6. The skinning resource management method applied to the iOS system according to claim 4, characterized in that, The step of binding the index of the multi-skin color array with the skin type order includes: The first element of the multi-skin color array corresponds to the default skin, the second element corresponds to the dark skin, and the third element corresponds to the holiday-limited skin. When a new skin is added, the color value corresponding to the new skin is appended to the end of the multi-skin color array of all color base classes.
7. The skinning resource management method applied to the iOS system according to claim 1, characterized in that, The steps of loading the image resource directory and color configuration file in the target skin corresponding to the target skin identifier include: The skin manager determines the corresponding package path of the target skin at runtime based on the target skin identifier; The image resource directory and color configuration file in the target skin are loaded via the package path so that subsequent resource access requests are redirected to the currently active target skin.
8. The skinning resource management method applied to the iOS system according to claim 1, characterized in that, The unified resource refresh interface is defined as the skin refresh process in the view control category; the steps of reloading image and color resources from the target skin through the unified resource refresh interface include: In the skin refresh process, the image loading process is called again to obtain the image from the image resource directory of the current target skin, and the color acquisition process is called again to obtain the color from the color configuration of the current target skin. Finally, the new resource is set to the property of the interface view control itself.
9. The skinning resource management method applied to an iOS system according to any one of claims 1 to 8, characterized in that, The skin-changing events include user actions of manually selecting skins through the settings interface or skin-switching events automatically triggered by the application according to preset rules.
10. A skin-changing resource management device for iOS system, characterized in that, A hierarchical architecture of a main project target and multiple skin targets is pre-constructed; wherein, the main project target is used to store business logic and skin-changing control interfaces, and each skin target serves as an independent compilation unit to store all resources of the corresponding skin; the main project target calls resources in the skin targets through preset dependencies; the device includes: The skin-changing response module is used to respond to the triggering of a skin-changing event and obtain the target skin identifier through the skin manager; wherein, the skin manager is a singleton object running in the main project target; The configuration loading module is used by the skin manager to update the current skin index to the index value corresponding to the target skin identifier according to the target skin identifier, and to load the image resource directory and color configuration file in the target skin corresponding to the target skin identifier; The skin notification module is used by the skin manager to send skin notifications to all UI view controls that are listening for skin notifications. The skin-changing execution module is used by the interface view control to respond to the skin-changing notification by reloading image resources and color resources from the target skin through a unified resource refresh interface to complete the interface skin-changing.