SLBlurView.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // SLBlurView.m
  3. // DarkMode
  4. //
  5. // Created by wsl on 2019/9/19.
  6. // Copyright © 2019 wsl. All rights reserved.
  7. //
  8. #import "SLBlurView.h"
  9. @implementation SLBlurView
  10. /*
  11. Only override drawRect: if you perform custom drawing.
  12. An empty implementation adversely affects performance during animation.
  13. */
  14. - (instancetype)initWithFrame:(CGRect)frame {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. self.clipsToBounds = YES;
  18. self.userInteractionEnabled = YES;
  19. [self addSubview:self.blurView];
  20. }
  21. return self;
  22. }
  23. - (instancetype)init {
  24. self = [super init];
  25. if (self) {
  26. self.clipsToBounds = YES;
  27. self.userInteractionEnabled = YES;
  28. [self addSubview:self.blurView];
  29. }
  30. return self;
  31. }
  32. - (UIVisualEffectView *)blurView {
  33. if (_blurView == nil) {
  34. //高斯模糊
  35. UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
  36. _blurView = [[UIVisualEffectView alloc] initWithEffect:blur];
  37. _blurView.alpha = 0.9;
  38. _blurView.frame = self.bounds;
  39. }
  40. return _blurView;
  41. }
  42. - (void)layoutSubviews {
  43. [self sendSubviewToBack:self.blurView];
  44. self.blurView.frame = self.bounds;
  45. }
  46. @end