Control color adjusting method and device, electronic equipment and storage medium
By selecting the adaptive drawing tools based on the control type and drawing content in iOS development, and determining the target context according to the color adjustment requirements, directly controlling the drawing tools for color adjustment, the problem of color combination calculation and storage in the existing technology is solved, real-time automatic adjustment of control colors and efficiency improvement is achieved.
Patent Information
- Application Number
- CN202411906606.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-15
AI Technical Summary
When the existing technology implements dynamic adjustment of control color in iOS development, a large number of color combinations need to be calculated offline in advance and stored, resulting in waste of storage space and increased system resource usage.
By determining the target control and its type and drawing content in the control list, selecting the appropriate drawing tool, and determining the target context according to the color adjustment requirements, directly adjusting the color through the target context control drawing tool.
Real-time automatic adjustment of control colors is realized, avoiding the early offline calculation and storage of a large number of color combinations, reducing waste of storage space and system resource usage, and improving the efficiency of control color adjustment.
Smart Images

Figure CN119829183A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of control display technology, and in particular to a control color adjustment method and device, electronic equipment, and storage medium. Background Art
[0002] In iOS development, the controls of the application interface need to adapt to a variety of theme styles, and the colors of the controls (including text color, background color, etc.) need to be dynamically adjusted with the theme color. In addition, some controls need to be mixed with the theme color according to their original colors to achieve more complex color adjustment visual effects, such as transparency gradient or multi-layer mixing.
[0003] In the related art, dynamic color mixing is usually achieved by pre-calculating the color mixing result of the control according to the theme color, storing it and assigning it to the control when the theme changes. For example, the developer needs to pre-calculate the control color under different transparency, different theme colors, and various combinations of the control's initial color, and pre-store all calculation results in the application.
[0004] However, the above solution requires offline calculation and storage of a large number of color combinations in advance, resulting in a waste of storage space and increasing the occupation of system resources. Summary of the invention
[0005] In view of the above problems, a control color adjustment method and device, electronic device, and storage medium are proposed to overcome the above problems or at least partially solve the above problems, including:
[0006] A control color adjustment method, characterized in that the method comprises:
[0007] Determine a target control in the control list, and determine the control type and drawing content of the target control; wherein the drawing content is visual information displayed by the target control;
[0008] Determining a drawing tool to be used for the target control according to the control type and the drawing content, and determining a target context corresponding to the color adjustment requirement in response to a color adjustment requirement of the target control;
[0009] According to the target context, the drawing tool is controlled to adjust the color of the target control.
[0010] Optionally, before determining the target context corresponding to the color adjustment requirement in response to the color adjustment requirement of the target control, the method further includes:
[0011] According to the drawing tool, context type information corresponding to the drawing tool is determined; wherein the context type information at least includes a plaintext context type and a current context type.
[0012] Optionally, determining a target context corresponding to the color adjustment requirement includes:
[0013] An original context corresponding to the drawing tool is determined according to the context type information, and the target context is determined according to the original context and the color adjustment requirement.
[0014] Optionally, determining the target context according to the original context and the color adjustment requirement includes:
[0015] According to the color adjustment requirement, parameters of the original context are set to obtain the target context, wherein the parameters at least include a color parameter and a transparency parameter.
[0016] Optionally, before determining the target control in the control list, the method further includes:
[0017] An original control list is obtained, and controls in the original control list are converted to obtain the control list; wherein the conversion process is used to convert the drawing mode of the controls into a drawing mode using a context.
[0018] Optionally, converting the controls in the original control list to obtain the control list includes:
[0019] Determine a drawing function of the control, and rewrite the drawing function to add relevant logic for applying the context;
[0020] According to the rewritten drawing function, the controls are converted to obtain the control list.
[0021] Optionally, the method further includes:
[0022] A mapping relationship between the control type of the target control and the drawing tool is determined, and the mapping relationship is archived.
[0023] A control color adjustment device, the device comprising:
[0024] A target control determination module is used to determine a target control in a control list, and determine a control type and drawing content of the target control;
[0025] A target context determination module, configured to determine a drawing tool to be used for the target control according to the control type and drawing content, and to determine a target context corresponding to the color adjustment requirement in response to a color adjustment requirement of the target control;
[0026] The color adjustment module is used to control the drawing tool to adjust the color of the target control according to the target context.
[0027] An electronic device comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the control color adjustment method as described above when executed by the processor.
[0028] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the control color adjustment method described above is implemented.
[0029] The embodiments of the present invention have the following advantages:
[0030] In an embodiment of the present invention, a target control is determined in a control list, and the control type and drawing content of the target control are determined; wherein the drawing content is the visual information that the target control needs to display; then, according to the control type and the drawing content, the drawing tool to be used for the target control is determined, and in response to the color adjustment demand of the target control, the target context corresponding to the color adjustment demand is determined; thereby, the color of the target control is adjusted in real time by controlling the drawing tool according to the target context, and an appropriate drawing tool can be selected according to the control type and the drawing content, and the target context corresponding to the color adjustment demand can be determined, and then the control color adjustment can be achieved by directly controlling the drawing tool through the target context, without the need to calculate and store a large number of color combinations offline in advance, thereby avoiding the waste of storage space, reducing the occupation of system resources, and improving the efficiency of control color adjustment. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0032] Figure 1 is a flowchart of a method for adjusting the color of a control provided by some embodiments of the present invention;
[0033] Figure 2 is an example diagram of an execution flow of determining an original context by a drawing tool of the present invention provided in some embodiments of the present invention;
[0034] Figure 3 is an example diagram of an execution flow of determining an original context by the drawing tool of the present invention provided in some embodiments of the present invention;
[0035] Figure 4 It is a structural schematic diagram of a control color adjustment device provided in some embodiments of the present invention. DETAILED DESCRIPTION
[0036] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0037] In iOS development, the controls of the application interface need to adapt to a variety of theme styles, and the colors of the controls (including text color, background color, etc.) need to be dynamically adjusted with the theme color. In addition, some controls need to be mixed with the theme color according to their original colors to achieve more complex color adjustment visual effects, such as transparency gradient or multi-layer mixing.
[0038] In the related art, dynamic color mixing is usually achieved by pre-calculating the color mixing result of the control according to the theme color, storing it and assigning it to the control when the theme changes. For example, the developer needs to pre-calculate the control color under different transparency, different theme colors, and various combinations of the control's initial color, and pre-store all calculation results in the application.
[0039] However, the above solution requires offline calculation and storage of a large number of color combinations in advance, resulting in a waste of storage space and increasing the occupation of system resources.
[0040] In the embodiment of the present invention, based on the core technical concept of selecting an adaptive drawing tool according to the control type and drawing content and determining the target context corresponding to the color adjustment requirement, the control color adjustment method in the related art is improved. The present invention will be described in detail below with reference to the accompanying drawings:
[0041] Reference Figure 1 , shows a flowchart of a control color adjustment method provided by some embodiments of the present invention, which may specifically include the following steps:
[0042] Step 101, determining a target control in a control list, and determining the control type and drawing content of the target control; wherein the drawing content is visual information that the target control needs to display;
[0043] In a specific implementation, controls that require color adjustment may include but are not limited to text controls, image controls, and view area controls, and therefore, the controls that require color adjustment may be counted first to obtain an original control list. For example, the contents of an original control list may include: UILabel control, UIView control, UIImage control, CALayer control, custom control A, and custom control B.
[0044] On this basis, the controls in the original control list can be converted to unify the drawing method of the controls into a drawing method using the context, thereby reducing the difficulty of management and improving the efficiency of color adjustment; generally speaking, each control is a subclass of UIView or a subclass of CALayer, and their drawing method is essentially implemented by using the context provided by the system, that is, each control has a series of drawing functions inherited from UIView or CALayer. For example, for the UIView series of controls, a more common example of its drawing series function is func draw(_rect:CGRect), hereinafter referred to as draw(_:), and for the CALayer control, a more common example of its drawing series function is func draw(in rect:CGRect), hereinafter referred to as draw(in:); and CALayer also includes the CALayerDelegate proxy function: -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx; hereinafter referred to as draw(_:in:).
[0045] Therefore, you can traverse each control in the original control list, and add additional logic to the control's drawing function by rewriting the corresponding drawing function or replacing the drawing function through method swapping technology: generate context or obtain context from other channels to use context to achieve drawing, and then set the specific drawing process of each control on this basis. It should be emphasized that in addition to method swapping technology (swizzle), hooks, runtime dynamic detection technology (KVO, KVC), decompilation technology and aspect technology can also be used to achieve replacement functions.
[0046] Furthermore, after completing the conversion of the controls in the original control list through the rewritten drawing function, a control list consisting of controls whose drawing methods are all using the context drawing method is obtained. At this time, the target control that needs to be color adjusted can be determined in the control list, and the control type and drawing content of the target control can be determined to implement the subsequent color adjustment control process; specifically, the control list is established according to the control type, and the drawing content is the visual information that the target control needs to display, such as text content, image content, etc.
[0047] In some embodiments of the present invention, before determining the target control in the control list, the method further includes:
[0048] An original control list is obtained, and controls in the original control list are converted to obtain the control list; wherein the conversion process is used to convert the drawing mode of the controls into a drawing mode using a context.
[0049] In actual applications, controls that need to be adjusted in color may include but are not limited to text controls, image controls, and view area controls. Therefore, the controls that need to be adjusted in color may be counted first to obtain an original control list. For example, the content of an original control list may be: UILabel control, UIView control, UIImage control, CALayer control, custom control A, and custom control B.
[0050] On this basis, the controls in the original control list can be converted to unify the drawing method of the controls into a drawing method using a context, thereby reducing the difficulty of management and improving the efficiency of color adjustment.
[0051] In some embodiments of the present invention, converting the controls in the original control list to obtain the control list includes:
[0052] Determine a drawing function of the control, and rewrite the drawing function to add relevant logic for applying the context;
[0053] According to the rewritten drawing function, the controls are converted to obtain the control list.
[0054] In actual applications, the controls in the original control list can be converted to unify the drawing method of the controls into a drawing method using the context, thereby reducing the difficulty of management and improving the efficiency of color adjustment; generally speaking, each control is a subclass of UIView or a subclass of CALayer, and their drawing method is essentially implemented by using the context provided by the system, that is, each control has a series of drawing functions inherited from UIView or CALayer. For example, for the UIView series of controls, a more common example of its drawing series function is funcdraw(_rect:CGRect), hereinafter referred to as draw(_:), and for the CALayer control, a more common example of its drawing series function is func draw(in rect:CGRect), hereinafter referred to as draw(in:); and CALayer also includes the CALayerDelegate proxy function: -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)ctx; hereinafter referred to as draw(_:in:).
[0055] Therefore, each control in the original control list can be traversed, and additional logic can be added to the control's drawing function by rewriting the corresponding drawing function or replacing the drawing function through method swapping technology: generating context or obtaining context from other channels to use context to achieve drawing, and then setting the specific drawing process of each control on this basis. It should be emphasized that in addition to method swapping technology (swizzle), hooks, runtime dynamic detection technology (KVO, KVC), decompilation technology and aspect technology can also be used to achieve replacement functions. After completing the conversion of the controls in the original control list through the rewritten drawing function, a control list consisting of controls whose drawing methods are all using the context drawing method is obtained.
[0056] Step 102, determining a drawing tool to be used for the target control according to the control type and drawing content, and determining a target context corresponding to the color adjustment requirement in response to a color adjustment requirement of the target control;
[0057] In the specific implementation, based on the above content, the premise for the control in the control list to achieve drawing is to obtain the corresponding context, that is, the context is the basis for all drawing of the control. How to obtain the context needs to be determined according to different situations, for example:
[0058] (1) For basic controls and custom controls inherited from UIView in the control list
[0059] You can rewrite its draw(_:) method so that the system automatically provides a context, and this context is the "current context";
[0060] (2) For basic controls and custom controls that inherit from CALayer in the control list
[0061] You can override the draw(in:) method or the draw(_:in:) method and pass the context as a function parameter. However, no matter which method you override, the context is not the "current context".
[0062] (3) For images or other drawing areas that need to be drawn immediately
[0063] You can use the UIGraphicsImageRenderer class to call the image(actions:) function for drawing. The system can automatically provide a context, and this context is the "current context"; the full name of the function is as follows:
[0064] func image(actions:(UIGraphicsImageRendererContext)->Void)->UIImage;
[0065] Furthermore, the drawing tools used in the embodiments of the present invention may include:
[0066] UIKit drawing tools:
[0067] UIKit provides some self-drawing tools, which have their own drawing functions and are easy to use. For example: UIImage, NSString, UIBezierPath and UIColor, so you can call the drawing function directly without the explicit participation of the context, but you need to use the current context. That is, when using UIKit tools to draw, you generally need to draw on the "current context" to take effect. If the context is not the "current context", the drawing will not take effect.
[0068] Core Graphics:
[0069] Core Graphics, also known as Quartz 2D, includes all 2D drawing tools, which are composed of C functions and are a superset of UIKit drawing tools. There is a requirement for drawing with this set of tools: it does not need to appear in the "current context", but it requires a context that appears in plain text (i.e. plain text context).
[0070] On this basis, the drawing tool to be used by the target control can be determined according to the control type and drawing content of the target control. For example, Figure 2 As shown, for controls inherited from UIView, if the drawing content is text or other simple drawing content, UIKit's drawing tools can be used. From the perspective of drawing content, functions that can be covered by functions such as UIImage, NSString, UIBezierPath, UIColor, etc. can all be stripped out and processed using UIKit's drawing tools, and the processing location is: put in UIView's draw(_:) method. However, this step is optional and can be determined according to the actual application situation. Because all functions that can be implemented using UIKit's drawing tools can be implemented through CoreGraphics. The rest of the drawing content that cannot be processed by UIKit drawing tools can be processed using CoreGraphics after being stripped out, because Core Graphics requires a plaintext context; therefore, if the current position is in the draw(_:) method of UIView, a plaintext context can be obtained through the UIGraphicsGetCurrentContext method; and if the current position is in the image(actions:) function of UIGraphicsImageRenderer, the input parameter can be obtained, which is the plaintext context; or the UIGraphicsGetCurrentContext method can be called to obtain a plaintext context.
[0071] Further, such as Figure 3As shown, for controls inherited from CALayer, if the drawing content is text or more complex drawing content, UIKit controls can be used; and from the perspective of drawing content, for functions that can be covered by UIImage, NSString, UIBezierPath, UIColor and other functions, they can be processed using UIKit drawing tools after being stripped out, and the processing location can be placed in CALayer's draw(in:) method or CALayerDelegate proxy function draw(_:in:). As mentioned earlier, in CALayer's draw(in:) method or CALayerDelegate proxy function draw(_:in:), although context appears in plain text, it is not the "current context", so in order to make the context the "current context", UIGraphicsPushContext(_:) needs to be called, and when it is finished, UIGraphicsPopContext needs to be called. Then you can strip out the rest of the content that can't be processed by UIKit drawing tools and use Core Graphics for processing. Since it requires a plaintext context, if the current position is in: CALayer's draw(in:) method or CALayerDelegate proxy function draw(_:in:), you can choose to get its input parameter, which is a plaintext context, or call the UIGraphicsGetCurrentContext method to get a plaintext context. If the current position is in: UIGraphicsImageRenderer's function image(actions:), you can choose to get its input parameter, which is a plaintext context, or call the UIGraphicsGetCurrentContext method to get a plaintext context.
[0072] After the above steps, you can determine the drawing tool to be used by the target control and get the original context corresponding to the drawing tool. Then, you can set the parameters of the original context according to the color adjustment requirements of the target control to get the target context, and implement subsequent control based on the target context. Specifically, both the UIKit drawing tool and the CoreGraphics drawing tool have methods for setting context, but the forms are different. Therefore, the following will take CoreGraphics as an example for explanation:
[0073] (1) Original coloring
[0074] When drawing the content of a control that requires color mixing, the use of colors is generally involved, for example:
[0075] Set the fill color:
[0076] context.setFillColor(xx.cgColor);
[0077] Set the stroke color:
[0078] context.setStrokeColor(xx.cgColor);
[0079] (2) Add transparency
[0080] You can add the steps to set the context transparency (alpha) after the color setting:
[0081] context.setAlpha (transparency value): Transparency determines the color mixing scheme. Assuming there are two layers, if the transparency is set to 0, the color of the lower layer is completely adopted. If the transparency is 1, the color of the upper layer is completely adopted. If the transparency is other values between 0-1, the color mixing result calculation formula can be:
[0082] result=alpha*upper+(1-alpha)*lower
[0083] And the color mixing result calculation formula can be changed to be more complicated, such as:
[0084] result = coefficient 1*alpha*upper + coefficient 2*(1-alpha)*lower
[0085] By changing this formula and adding more layers, you can define a very complex color mixing scheme. The default mode can be the simplest mode mentioned above. For example, for multiple layers, you can start from the bottom layer and use the results of the bottom two layers as the input for comparison with the third layer above. You can calculate the final transparency of multiple layers. You can also form a result for each adjacent two layers for multiple layers (if there are an odd number of layers, they will not be included in the calculation and enter the next result list), and then gather the results into a new list, and then perform adjacent calculations on the elements in the list again until a final result is obtained.
[0086] Through the above steps, the target context corresponding to the color adjustment requirement can be determined, which can be used in the subsequent color adjustment control process.
[0087] In some embodiments of the present invention, before determining the target context corresponding to the color adjustment requirement in response to the color adjustment requirement of the target control, the method further includes:
[0088] According to the drawing tool, context type information corresponding to the drawing tool is determined; wherein the context type information at least includes a plaintext context type and a current context type.
[0089] In actual applications, the drawing tool to be used by the target control can be determined according to the control type and drawing content of the target control, and the context type information corresponding to the drawing tool can be further determined according to the drawing tool, that is, whether the drawing tool needs to use the plaintext context type (plaintext context) or the current context type (current context). For example, Figure 2 As shown, for controls inherited from UIView, if the drawing content is text or other simple drawing content, UIKit's drawing tools can be used. From the perspective of drawing content, the functions that can be covered by functions such as UIImage, NSString, UIBezierPath, UIColor, etc. can all be stripped out and processed using UIKit's drawing tools, and the processing location is: put in UIView's draw(_:) method. However, this step is optional and can be determined according to the actual application situation. Because all functions that can be implemented using UIKit's drawing tools can be implemented through Core Graphics. The rest of the drawing content that cannot be processed by UIKit drawing tools can be processed using Core Graphics after being stripped out, because Core Graphics requires a plaintext context; therefore, if the current position is in: UIView's draw(_:) method, you can get a plaintext context through the UIGraphicsGetCurrentContext method; and if the current position is in: UIGraphicsImageRenderer's function image(actions:), you can get its input parameter, which is the plaintext context; or call the UIGraphicsGetCurrentContext method to get a plaintext context.
[0090] Further, such as Figure 3As shown, for controls inherited from CALayer, if the drawing content is text or more complex drawing content, UIKit controls can be used; and from the perspective of drawing content, for functions that can be covered by UIImage, NSString, UIBezierPath, UIColor and other functions, they can be processed using UIKit drawing tools after being stripped out, and the processing location can be placed in CALayer's draw(in:) method or CALayerDelegate proxy function draw(_:in:). As mentioned earlier, in CALayer's draw(in:) method or CALayerDelegate proxy function draw(_:in:), although context appears in plain text, it is not the "current context", so in order to make the context the "current context", UIGraphicsPushContext(_:) needs to be called, and when it is finished, UIGraphicsPopContext needs to be called. Then you can strip out the rest of the content that can't be processed by UIKit drawing tools and use Core Graphics for processing. Since it requires a plaintext context, if the current position is in: CALayer's draw(in:) method or CALayerDelegate proxy function draw(_:in:), you can choose to get its input parameter, which is a plaintext context, or call the UIGraphicsGetCurrentContext method to get a plaintext context. If the current position is in: UIGraphicsImageRenderer's function image(actions:), you can choose to get its input parameter, which is a plaintext context, or call the UIGraphicsGetCurrentContext method to get a plaintext context.
[0091] In some embodiments of the present invention, determining the target context corresponding to the color adjustment requirement includes:
[0092] An original context corresponding to the drawing tool is determined according to the context type information, and the target context is determined according to the original context and the color adjustment requirement.
[0093] In actual applications, the drawing tool to be used by the target control can be determined according to the control type and drawing content of the target control, and the context type information corresponding to the drawing tool can be further determined according to the drawing tool, that is, whether the drawing tool needs to use the plaintext context type (plaintext context) or the current context type (current context), and then the corresponding original context is obtained according to the corresponding context type. For example, Figure 2 As shown, for controls inherited from UIView, if the drawing content is text or other simple drawing content, UIKit's drawing tools can be used. From the perspective of drawing content, the functions that can be covered by functions such as UIImage, NSString, UIBezierPath, UIColor, etc. can all be stripped out and processed using UIKit's drawing tools, and the processing location is: put in UIView's draw(_:) method. However, this step is optional and can be determined according to the actual application situation. Because all functions that can be implemented using UIKit's drawing tools can be implemented through Core Graphics. The rest of the drawing content that cannot be processed by UIKit drawing tools can be processed using Core Graphics after being stripped out, because Core Graphics requires a plaintext context; therefore, if the current position is in: UIView's draw(_:) method, you can get a plaintext context through the UIGraphicsGetCurrentContext method; and if the current position is in: UIGraphicsImageRenderer's function image(actions:), you can get its input parameter, which is the plaintext context; or call the UIGraphicsGetCurrentContext method to get a plaintext context.
[0094] In some embodiments of the present invention, determining the target context according to the original context and the color adjustment requirement includes:
[0095] According to the color adjustment requirement, parameters of the original context are set to obtain the target context, wherein the parameters at least include a color parameter and a transparency parameter.
[0096] In actual applications, after determining the drawing tool to be used by the target control and obtaining the original context corresponding to the drawing tool, the parameters of the original context can be set according to the color adjustment requirements of the target control to obtain the target context, and subsequent control can be implemented according to the target context; specifically, both the UIKit drawing tool and the Core Graphics drawing tool have methods for setting context, but the forms are different. Therefore, the following will take Core Graphics as an example for explanation:
[0097] (1) Original color filling (color parameter setting)
[0098] When drawing the content of a control that requires color mixing, the use of colors is generally involved, for example:
[0099] Set the fill color:
[0100] context.setFillColor(xx.cgColor);
[0101] Set the stroke color:
[0102] context.setStrokeColor(xx.cgColor);
[0103] (2) Transparency added (transparency parameter setting)
[0104] You can add the steps to set the context transparency (alpha) after the color setting:
[0105] context.setAlpha (transparency value): Transparency determines the color mixing scheme. Assuming there are two layers, if the transparency is set to 0, the color of the lower layer is completely adopted. If the transparency is 1, the color of the upper layer is completely adopted. If the transparency is other values between 0-1, the color mixing result calculation formula can be:
[0106] result=alpha*upper+(1-alpha)*lower
[0107] And the color mixing result calculation formula can be changed to be more complicated, such as:
[0108] result = coefficient 1*alpha*upper + coefficient 2*(1-alpha)*lower
[0109] By changing this formula and adding more layers, you can define a very complex color mixing scheme. The default mode can be the simplest mode mentioned above. For example, for multiple layers, you can start from the bottom layer and use the results of the bottom two layers as the input for comparison with the third layer above. You can calculate the final transparency of multiple layers. You can also form a result for each adjacent two layers for multiple layers (if there are an odd number of layers, they will not be included in the calculation and enter the next result list), and then gather the results into a new list, and then perform adjacent calculations on the elements in the list again until a final result is obtained.
[0110] Through the above steps, the target context corresponding to the color adjustment requirement can be determined, which can be used in the subsequent color adjustment control process.
[0111] Step 103: Control the drawing tool to adjust the color of the target control according to the target context.
[0112] In the specific implementation, after setting the relevant parameters to determine the final target context, the drawing tool can be controlled according to the target context to adjust the color of the target control. Specifically, since the transparency and color mixing scheme have been specified on the context, the system can directly calculate the final result (i.e., the color mixing result) for the newly added color when adjusting the color. That is, the original target control has one color, and when the new color is added, it only needs to directly assign the new color to the target control, and then call the corresponding refresh function provided by the system (such as setNeedsDisplay / layoutIfNeeded, etc.), without calculation.
[0113] For example, in actual use, if there is no color mixing scheme and you want the new color to become the color of the control directly, you can simply set the alpha here to 1. If there is a color mixing scheme and you want the new color to be mixed with the old color and then become the color of the control, you can set the alpha here to the alpha value calculated by the color mixing result calculation formula in the previous step. If there is no color mixing scheme and you do not want the new color to affect the old color, you can set the alpha here to 0.
[0114] Furthermore, after a round of statistics, the alpha value corresponding to each control can be recorded in a mapping relationship to facilitate synchronization with other devices and app versions, as well as saving and other operations; the mapping relationship between the control type of the target control and the drawing tool can also be archived to facilitate direct calls in response to subsequent similar or identical control color adjustment requirements.
[0115] In some embodiments of the present invention, the method further comprises:
[0116] A mapping relationship between the control type of the target control and the drawing tool is determined, and the mapping relationship is archived.
[0117] In actual applications, as mentioned above, after a round of statistics, the alpha value corresponding to each control can be recorded in a mapping relationship to facilitate synchronization with other devices and app versions, as well as saving and other operations; the mapping relationship between the control type of the target control and the drawing tool can also be archived to facilitate direct calls in response to subsequent similar or identical control color adjustment requirements.
[0118] In an embodiment of the present invention, a target control is determined in a control list, and the control type and drawing content of the target control are determined; wherein the drawing content is the visual information that the target control needs to display; then, according to the control type and the drawing content, the drawing tool to be used for the target control is determined, and in response to the color adjustment demand of the target control, the target context corresponding to the color adjustment demand is determined; thereby, the color of the target control is adjusted in real time by controlling the drawing tool according to the target context, and an appropriate drawing tool can be selected according to the control type and the drawing content, and the target context corresponding to the color adjustment demand can be determined, and then the control color adjustment can be achieved by directly controlling the drawing tool through the target context, without the need to calculate and store a large number of color combinations offline in advance, thereby avoiding the waste of storage space, reducing the occupation of system resources, and improving the efficiency of control color adjustment.
[0119] It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.
[0120] Reference Figure 4 , shows a schematic diagram of the structure of a control color adjustment device provided by some embodiments of the present invention, which may specifically include the following modules:
[0121] The target control determination module 401 is used to determine the target control in the control list, and determine the control type and drawing content of the target control;
[0122] The target context determination module 402 is used to determine the drawing tool to be used for the target control according to the control type and the drawing content, and to determine the target context corresponding to the color adjustment requirement in response to the color adjustment requirement of the target control;
[0123] The color adjustment module 403 is used to control the drawing tool to adjust the color of the target control according to the target context.
[0124] In some embodiments of the present invention, the target context determination module 402 includes:
[0125] The context type determination submodule is used to determine the context type information corresponding to the drawing tool according to the drawing tool; wherein the context type information at least includes a plain text context type and a current context type.
[0126] In some embodiments of the present invention, the target context determination module 402 includes:
[0127] The target context determination submodule is used to determine the original context corresponding to the drawing tool according to the context type information, and determine the target context according to the original context and the color adjustment requirement.
[0128] In some embodiments of the present invention, the target context determination submodule includes:
[0129] A parameter setting unit is used to set parameters of the original context according to the color adjustment requirement to obtain the target context, wherein the parameters at least include a color parameter and a transparency parameter.
[0130] In some embodiments of the present invention, the device further comprises:
[0131] The conversion processing module is used to obtain an original control list and perform conversion processing on the controls in the original control list to obtain the control list; wherein the conversion processing is used to convert the drawing method of the controls into a drawing method using a context.
[0132] In some embodiments of the present invention, the conversion processing module includes:
[0133] A function rewriting submodule, used for determining a drawing function of the control and rewriting the drawing function to add relevant logic for applying the context;
[0134] The conversion processing submodule is used to perform conversion processing on the controls according to the rewritten drawing function to obtain the control list.
[0135] In some embodiments of the present invention, the device further comprises:
[0136] The mapping relationship archiving module is used to determine the mapping relationship between the control type of the target control and the drawing tool, and to archive the mapping relationship.
[0137] Some embodiments of the present invention further provide an electronic device, which may include a processor, a memory, and a computer program stored in the memory and capable of running on the processor, and when the computer program is executed by the processor, the above control color adjustment method is implemented.
[0138] Some embodiments of the present invention further provide a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the control color adjustment method as described above is implemented.
[0139] Some embodiments of the present invention further provide a computer program product, including a computer program, which implements the above control color adjustment method when executed by a processor.
[0140] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0141] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0142] Those skilled in the art will appreciate that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0143] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0144] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0145] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0146] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0147] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "including one..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the above elements.
[0148] The above provides a detailed introduction to a control color adjustment method and device, electronic device, and storage medium. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technicians in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A control color adjustment method, characterized in that: The method comprises: Determine a target control in the control list, and determine the control type and drawing content of the target control; wherein the drawing content is visual information that the target control needs to display; Determining a drawing tool to be used for the target control according to the control type and the drawing content, and determining a target context corresponding to the color adjustment requirement in response to a color adjustment requirement of the target control; According to the target context, the drawing tool is controlled to adjust the color of the target control.
2. The method according to claim 1, characterized in that: Before the step of determining the target context corresponding to the color adjustment requirement in response to the color adjustment requirement of the target control, the method further includes: According to the drawing tool, context type information corresponding to the drawing tool is determined; wherein the context type information at least includes a plaintext context type and a current context type.
3. The method according to claim 2, characterized in that The determining the target context corresponding to the color adjustment requirement includes: An original context corresponding to the drawing tool is determined according to the context type information, and the target context is determined according to the original context and the color adjustment requirement.
4. The method according to claim 3, characterized in that The determining the target context according to the original context and the color adjustment requirement includes: According to the color adjustment requirement, parameters of the original context are set to obtain the target context, wherein the parameters at least include a color parameter and a transparency parameter.
5. The method according to claim 1, characterized in that Before determining the target control in the control list, the method further includes: An original control list is obtained, and controls in the original control list are converted to obtain the control list; wherein the conversion process is used to convert the drawing mode of the controls into a drawing mode using a context.
6. The method according to claim 5, characterized in that The converting of the controls in the original control list to obtain the control list includes: Determine a drawing function of the control, and rewrite the drawing function to add relevant logic for applying the context; According to the rewritten drawing function, the controls are converted to obtain the control list.
7. The method according to claim 1, characterized in that The method further comprises: A mapping relationship between the control type of the target control and the drawing tool is determined, and the mapping relationship is archived.
8. A control color adjustment device, characterized in that: The device comprises: A target control determination module is used to determine a target control in a control list, and determine a control type and drawing content of the target control; A target context determination module, configured to determine a drawing tool to be used for the target control according to the control type and drawing content, and to determine a target context corresponding to the color adjustment requirement in response to a color adjustment requirement of the target control; The color adjustment module is used to control the drawing tool to adjust the color of the target control according to the target context.
9. An electronic device, characterized in that: The invention comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein the computer program implements the control color adjustment method according to any one of claims 1 to 7 when executed by the processor.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the control color adjustment method according to any one of claims 1 to 7 is implemented.