Guest User

Untitled

a guest
Nov 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. @implementation GradientView {
  2. CAGradientLayer *_gradientLayer;
  3. }
  4. @synthesize backgroundGradientTopColor, backgroundGradientBottomColor, backgroundGradientColors;
  5.  
  6. - (id)initWithFrame:(CGRect)frame
  7. {
  8. if ((self=[super initWithFrame:frame])) {
  9. _gradientLayer = [CAGradientLayer layer];
  10. _gradientLayer.zPosition = -1;
  11. _gradientLayer.opaque = NO;
  12. _gradientLayer.actions = [NSDictionary dictionaryWithObject:[CABasicAnimation animationWithKeyPath:@"colors"] forKey:@"colors"];
  13. [self.layer addSublayer:_gradientLayer];
  14.  
  15. self.opaque = NO;
  16. }
  17. return self;
  18. }
  19.  
  20. - (void)layoutSubviews
  21. {
  22. [super layoutSubviews];
  23. _gradientLayer.frame = self.layer.bounds;
  24. }
  25.  
  26. - (void)setBackgroundGradientColors:(NSArray *)inputColors
  27. {
  28. backgroundGradientColors = [inputColors copy];
  29.  
  30. //_gradientLayer.opaque = NO;
  31.  
  32. if ([backgroundGradientColors count] > 1) {
  33. NSMutableArray *colors = [NSMutableArray arrayWithCapacity:2];
  34.  
  35. for (UIColor *c in backgroundGradientColors) {
  36. [colors addObject:(id)c.CGColor];
  37. }
  38.  
  39. _gradientLayer.backgroundColor = nil;
  40. _gradientLayer.colors = colors;
  41. } else {
  42. _gradientLayer.backgroundColor = [[backgroundGradientColors lastObject] CGColor];
  43. _gradientLayer.colors = nil;
  44. }
  45. }
  46.  
  47. - (void)updateGradientColors
  48. {
  49. /*
  50. NSMutableArray *colors = [NSMutableArray arrayWithCapacity:2];
  51.  
  52. if (self.backgroundGradientTopColor) {
  53. [colors addObject:self.backgroundGradientTopColor];
  54. }
  55.  
  56. if (self.backgroundGradientBottomColor) {
  57. [colors addObject:self.backgroundGradientBottomColor];
  58. }
  59.  
  60. self.backgroundGradientColors = colors;
  61. */
  62. }
  63.  
  64. - (void)setBackgroundGradientTopColor:(UIColor *)c
  65. {
  66. /*
  67. if (![backgroundGradientTopColor isEqual:c]) {
  68. backgroundGradientTopColor = c;
  69. [self updateGradientColors];
  70. }
  71. */
  72. }
  73.  
  74. - (void)setBackgroundGradientBottomColor:(UIColor *)c
  75. {
  76. /*
  77. if (![backgroundGradientBottomColor isEqual:c]) {
  78. backgroundGradientBottomColor = c;
  79. [self updateGradientColors];
  80. }
  81. */
  82. }
  83.  
  84. @end
Add Comment
Please, Sign In to add comment