1. Open the xib file and select the view control that needs to add a border, the effect is shown in the figure
2. Click the "+" sign in the above figure to add attributes
// 圆角
layer.masksToBounds
layer.cornerRadius
// 边框
layer.borderWidth
layer.borderColorFromUIColor
3. After adding these, you will find that the border color is not displayed, and you need to add some CALayer
extension files. The code is as follows:
@interface CALayer (Category)
- (void)setBorderColorFromUIColor:(UIColor *)color;
@end
@implementation CALayer (Category)
- (void)setBorderColorFromUIColor:(UIColor *)color {
self.borderColor = color.CGColor;
}
@end
4. After adding these and running again, the border color will appear.