Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @implementation GradientView {
- CAGradientLayer *_gradientLayer;
- }
- @synthesize backgroundGradientTopColor, backgroundGradientBottomColor, backgroundGradientColors;
- - (id)initWithFrame:(CGRect)frame
- {
- if ((self=[super initWithFrame:frame])) {
- _gradientLayer = [CAGradientLayer layer];
- _gradientLayer.zPosition = -1;
- _gradientLayer.opaque = NO;
- _gradientLayer.actions = [NSDictionary dictionaryWithObject:[CABasicAnimation animationWithKeyPath:@"colors"] forKey:@"colors"];
- [self.layer addSublayer:_gradientLayer];
- self.opaque = NO;
- }
- return self;
- }
- - (void)layoutSubviews
- {
- [super layoutSubviews];
- _gradientLayer.frame = self.layer.bounds;
- }
- - (void)setBackgroundGradientColors:(NSArray *)inputColors
- {
- backgroundGradientColors = [inputColors copy];
- //_gradientLayer.opaque = NO;
- if ([backgroundGradientColors count] > 1) {
- NSMutableArray *colors = [NSMutableArray arrayWithCapacity:2];
- for (UIColor *c in backgroundGradientColors) {
- [colors addObject:(id)c.CGColor];
- }
- _gradientLayer.backgroundColor = nil;
- _gradientLayer.colors = colors;
- } else {
- _gradientLayer.backgroundColor = [[backgroundGradientColors lastObject] CGColor];
- _gradientLayer.colors = nil;
- }
- }
- - (void)updateGradientColors
- {
- /*
- NSMutableArray *colors = [NSMutableArray arrayWithCapacity:2];
- if (self.backgroundGradientTopColor) {
- [colors addObject:self.backgroundGradientTopColor];
- }
- if (self.backgroundGradientBottomColor) {
- [colors addObject:self.backgroundGradientBottomColor];
- }
- self.backgroundGradientColors = colors;
- */
- }
- - (void)setBackgroundGradientTopColor:(UIColor *)c
- {
- /*
- if (![backgroundGradientTopColor isEqual:c]) {
- backgroundGradientTopColor = c;
- [self updateGradientColors];
- }
- */
- }
- - (void)setBackgroundGradientBottomColor:(UIColor *)c
- {
- /*
- if (![backgroundGradientBottomColor isEqual:c]) {
- backgroundGradientBottomColor = c;
- [self updateGradientColors];
- }
- */
- }
- @end
Add Comment
Please, Sign In to add comment