IOS adds the color of the rounded corner, outer frame, and outer frame to the control in xib or storyboard.
If you want to add the rounded corner and the width of the outer frame to the control in xib and storyboard, you only need to do so.
Layer. borderWidth: Set the out-of-box width attribute.
Layer. cornerRadius
You only need to set the value for the attribute.
Of course, it cannot be seen after xib is modified. The result is as follows:
What should I do if I want to modify the color of the outer box in xib and storyboard ?? Only other methods can be implemented, such as classification.
Add category
Then
Generate this file
. H file
1 #import <QuartzCore/QuartzCore.h>2 3 @interface CALayer (LayerColor)4 5 - (void)setBorderColorFromUIColor:(UIColor *)color;6 7 @end
In the. m file
Add a set method
1 #import "CALayer+LayerColor.h" 2 3 @implementation CALayer (LayerColor) 4 5 - (void)setBorderColorFromUIColor:(UIColor *)color 6 { 7 self.borderColor = color.CGColor; 8 } 9 10 @end
If your UIColor prompts that the error cannot be found, you have not imported the UIKit framework.
Import It In The. h or global header file.
# Import <UIKit/UIKit. h>
This completes the basic work.
Now you can add this attribute in the xib or storyboard just like adding a control outer box and a rounded corner.
Type is color
Note that this is the set method, so if the method added in the category is
-(Void) setBorderColorFromUIColor :( UIColor *) color;
The attribute should be layer. borderColorFromUIColor.
For example
-(Void) setColorFromUIColor :( UIColor *) color;
The attribute is layer. colorFromUIColor.
Run:
In this way, we can understand how this method is used. Otherwise, the color setting is invalid because the method is incorrect.