直接看看这块代码。
其实可以发现,
CAShapeLayer *_layerRight;
UIBezierPath *_pathLeft;
#import <UIKit/UIKit.h>
@interface XWSectionPlatView : UIView
@property (nonatomic,strong) UIColor *leftColor;
@property (nonatomic,strong) UIColor *rightColor;
@property (nonatomic,assign) CGFloat leftSpan;
@end
#import "XWSectionPlatView.h"
@implementation XWSectionPlatView
{
CAShapeLayer *_layerLeft;
CAShapeLayer *_layerRight;
UIBezierPath *_pathLeft;
UIBezierPath *_pathRight;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
_leftSpan =self.frame.size.width * 0.25;
_layerLeft = [[CAShapeLayeralloc] init];
_layerRight = [[CAShapeLayeralloc] init];
_layerLeft.fillColor =nil;
_layerRight.fillColor =nil;
_layerLeft.frame =self.bounds;
_layerRight.frame =self.bounds;
self.backgroundColor = [UIColorblueColor];
}
returnself;
}
- (void)setLeftLayer{
_pathLeft = [UIBezierPathbezierPathWithRect:CGRectMake(0, 0,_leftSpan, self.frame.size.height)];
_layerLeft.path =_pathLeft.CGPath;
}
- (void)setRightLayer{
_pathRight = [UIBezierPathbezierPathWithRect:CGRectMake(_leftSpan, 0,self.frame.size.width - _leftSpan, self.frame.size.height)];
}
- (void)setLeftSpan:(CGFloat)leftSpan {
_leftSpan = leftSpan;
[selfsetRightLayer];
[selfsetLeftLayer];
}
- (void)setRightColor:(UIColor *)rightColor {
_layerRight.fillColor = rightColor.CGColor;
[selfsetRightLayer];
}
- (void)setLeftColor:(UIColor *)leftColor {
_layerLeft.fillColor = leftColor.CGColor;
[selfsetLeftLayer];
}
@end