UIView+Effect.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // UIView+Effect.m
  3. // CommonLibrary
  4. //
  5. // Created by AlexiChen on 15/12/24.
  6. // Copyright © 2015年 AlexiChen. All rights reserved.
  7. //
  8. #import "UIView+Effect.h"
  9. #import "IOSDeviceConfig.h"
  10. #import "UIImage+Common.h"
  11. #import "UIImage+ImageEffect.h"
  12. @implementation UIView (Effect)
  13. - (void)blurWithColor:(UIColor *)color
  14. {
  15. UIImage *image = [UIImage imageWithColor:color size:CGSizeMake(32, 32)];
  16. [self blurWithImage:image];
  17. }
  18. // 底层自动blur image
  19. - (void)blurWithImage:(UIImage *)image
  20. {
  21. // if ([IOSDeviceConfig sharedConfig].isIOS7Later)
  22. // {
  23. // [self blurSelfAfterIOS7];
  24. // }
  25. // else
  26. // {
  27. UIImage *blurimg = [image applyLightEffect];
  28. UIImageView *effectView = [[UIImageView alloc] init];
  29. effectView.image = blurimg;
  30. effectView.autoresizesSubviews = YES;
  31. effectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  32. [self insertSubview:effectView atIndex:0];
  33. // }
  34. }
  35. - (void)blurSelfAfterIOS7
  36. {
  37. UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  38. effectView.autoresizesSubviews = YES;
  39. effectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  40. effectView.alpha = 1;
  41. [self insertSubview:effectView atIndex:0];
  42. }
  43. - (void)blurSelfBackground
  44. {
  45. // if ([IOSDeviceConfig sharedConfig].isIOS7Later)
  46. // {
  47. // [self blurSelfAfterIOS7];
  48. // }
  49. // else
  50. // {
  51. [self blurWithColor:[[UIColor flatDarkWhiteColor] colorWithAlphaComponent:0.8]];
  52. // }
  53. }
  54. @end