Guest User

Untitled

a guest
Jan 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. IB_DESIGNABLE
  2.  
  3. @interface FadingView ()
  4.  
  5. @property (assign, nonatomic) IBInspectable BOOL verticalFade;
  6. @property (assign, nonatomic) IBInspectable BOOL horizontalFade;
  7.  
  8. @end
  9.  
  10. @implementation FadingView
  11.  
  12. - (void)drawRect:(CGRect)rect {
  13. [super drawRect:rect];
  14.  
  15. self.opaque = NO;
  16. self.backgroundColor = UIColor.clearColor;
  17.  
  18. if (!self.layer.mask && (self.verticalFade || self.horizontalFade)) {
  19. NSArray *colors = @[
  20. (id) UIColor.clearColor.CGColor,
  21. (id) UIColor.whiteColor.CGColor,
  22. (id) UIColor.whiteColor.CGColor,
  23. (id) UIColor.clearColor.CGColor
  24. ];
  25.  
  26. CAGradientLayer *gradient = [[CAGradientLayer alloc] init];
  27. gradient.locations = @[@0, @0.05, @0.95, @1];
  28. gradient.colors = colors;
  29. gradient.frame = self.bounds;
  30.  
  31. if (self.horizontalFade) {
  32. gradient.frame = self.bounds;
  33. gradient.startPoint = CGPointZero;
  34. gradient.endPoint = CGPointMake(1, 0);
  35. }
  36.  
  37. self.layer.mask = gradient;
  38. }
  39. }
  40.  
  41. @end
Add Comment
Please, Sign In to add comment