AvatarBackgroundImageView.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. #import "AvatarBackgroundImageView.h"
  6. @implementation GradientView
  7. @dynamic layer;
  8. + (Class)layerClass {
  9. return [CAGradientLayer class];
  10. }
  11. @end
  12. @implementation AvatarBackgroundImageView
  13. - (instancetype)init
  14. {
  15. self = [super init];
  16. if (self) {
  17. [self initGradientLayer];
  18. }
  19. return self;
  20. }
  21. - (instancetype)initWithFrame:(CGRect)frame
  22. {
  23. self = [super initWithFrame:frame];
  24. if (self) {
  25. [self initGradientLayer];
  26. }
  27. return self;
  28. }
  29. - (instancetype)initWithImage:(UIImage *)image
  30. {
  31. self = [super initWithImage:image];
  32. if (self) {
  33. [self initGradientLayer];
  34. }
  35. return self;
  36. }
  37. - (instancetype)initWithCoder:(NSCoder *)aDecoder
  38. {
  39. self = [super initWithCoder:aDecoder];
  40. if (self) {
  41. [self initGradientLayer];
  42. }
  43. return self;
  44. }
  45. - (void)initGradientLayer
  46. {
  47. _gradientView = [[GradientView alloc] initWithFrame:self.bounds];
  48. _gradientView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  49. _gradientView.layer.colors = @[(id)[[UIColor colorWithWhite:0 alpha:0.6] CGColor], (id)[[UIColor colorWithWhite:0 alpha:0.6] CGColor]];
  50. _gradientView.layer.locations = @[@0.0, @1.0];
  51. [self addSubview:_gradientView];
  52. }
  53. - (void)layoutSubviews
  54. {
  55. [super layoutSubviews];
  56. // _gradientLayer.frame = self.bounds;
  57. }
  58. @end