线性垂直物镜c FSCalender的渐变填充

时间:2019-01-07 05:57:46

标签: ios objective-c fscalendar

我正在尝试在选定的日期进行贝塞尔曲线路径填充。我获得的是enter image description here

我需要的是enter image description here

这是我的代码

[super layoutSubviews];
[self.titleLabel sizeToFit];
self.titleLabel.center = self.contentView.center;

self.backgroundView.frame = CGRectInset(self.bounds, 5, 5);
self.circleImageView.frame = self.backgroundView.frame;

CGRect Fr_bounds = self.backgroundView.frame;
Fr_bounds.origin.x = self.bounds.origin.x;
Fr_bounds.origin.y = self.bounds.origin.y;
Fr_bounds.size.height = self.bounds.size.height;
Fr_bounds.size.width = self.bounds.size.width;

self.selectionLayer.frame = Fr_bounds;


UIBezierPath *path_layer;

if (self.selectionType == SelectionTypeMiddle) {

    path_layer = [UIBezierPath bezierPathWithRect:self.selectionLayer.bounds];

} else if (self.selectionType == SelectionTypeLeftBorder) {

    path_layer = [UIBezierPath bezierPathWithRoundedRect:self.selectionLayer.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerBottomLeft cornerRadii:CGSizeMake(self.selectionLayer.fs_width/2, self.selectionLayer.fs_width/2)];

} else if (self.selectionType == SelectionTypeRightBorder) {

    path_layer = [UIBezierPath bezierPathWithRoundedRect:self.selectionLayer.bounds byRoundingCorners:UIRectCornerTopRight|UIRectCornerBottomRight cornerRadii:CGSizeMake(self.selectionLayer.fs_width/2, self.selectionLayer.fs_width/2)];

} else if (self.selectionType == SelectionTypeSingle) {

    CGFloat diameter = MIN(self.selectionLayer.fs_height, self.selectionLayer.fs_width);
    path_layer = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(self.contentView.fs_width/2-diameter/2, self.contentView.fs_height/2-diameter/2, diameter, diameter)];

}

self.selectionLayer.path = path_layer.CGPath;



CAShapeLayer *gradientMask = [CAShapeLayer layer];
gradientMask.fillColor = [[UIColor blackColor] CGColor];
gradientMask.frame = CGRectMake(0, 0, self.fs_width, self.selectionLayer.frame.size.height);
gradientMask.path = path_layer.CGPath;

CAGradientLayer *gradientLayer = [CAGradientLayer layer];

gradientLayer.startPoint = CGPointMake(1.0, 0.0);
gradientLayer.endPoint = CGPointMake(0.0, 1.0);

gradientLayer.frame = CGRectMake(0, 0, self.fs_width, self.selectionLayer.frame.size.height);


gradientLayer.colors = @[(id)[UIColor colorWithRed:0.39 green:0.42 blue:0.85 alpha:1.0].CGColor,(id)[UIColor colorWithRed:0.38 green:0.80 blue:0.85 alpha:1.0].CGColor];

[gradientLayer setMask:gradientMask];
[self.selectionLayer addSublayer:gradientLayer];

我正在使用FSCalender并自定义DIY单元以实现此目的。如果选择类型为中,则无法在DIY单元中获得选定单元,也无法获得选定单元的Beizer路径

预先感谢

0 个答案:

没有答案
相关问题