Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IB_DESIGNABLE
- @interface FadingView ()
- @property (assign, nonatomic) IBInspectable BOOL verticalFade;
- @property (assign, nonatomic) IBInspectable BOOL horizontalFade;
- @end
- @implementation FadingView
- - (void)drawRect:(CGRect)rect {
- [super drawRect:rect];
- self.opaque = NO;
- self.backgroundColor = UIColor.clearColor;
- if (!self.layer.mask && (self.verticalFade || self.horizontalFade)) {
- NSArray *colors = @[
- (id) UIColor.clearColor.CGColor,
- (id) UIColor.whiteColor.CGColor,
- (id) UIColor.whiteColor.CGColor,
- (id) UIColor.clearColor.CGColor
- ];
- CAGradientLayer *gradient = [[CAGradientLayer alloc] init];
- gradient.locations = @[@0, @0.05, @0.95, @1];
- gradient.colors = colors;
- gradient.frame = self.bounds;
- if (self.horizontalFade) {
- gradient.frame = self.bounds;
- gradient.startPoint = CGPointZero;
- gradient.endPoint = CGPointMake(1, 0);
- }
- self.layer.mask = gradient;
- }
- }
- @end
Add Comment
Please, Sign In to add comment