当前位置:   article > 正文

[iOS]渐变毛玻璃效果_uiblureffectstyle

uiblureffectstyle

如示意图这种需求,对背景图片添加毛玻璃效果,再添加渐变颜色。
如图

实现

  1. #import "ViewController.h"
  2. @interface ViewController ()
  3. @property (weak, nonatomic) IBOutlet UIImageView *backImageView;
  4. @end
  5. @implementation ViewController
  6. - (void)viewDidLoad {
  7. [super viewDidLoad];
  8. [self frostedGlassViewStyle];
  9. }
  10. /* NS_ENUM_AVAILABLE_IOS(8_0)
  11. * UIBlurEffectStyleExtraLight, // 额外亮度,(高亮风格)
  12. * UIBlurEffectStyleLight, // 亮风格
  13. * UIBlurEffectStyleDark, // 暗风格
  14. * UIBlurEffectStyleExtraDark __TVOS_AVAILABLE(10_0) __IOS_PROHIBITED __WATCHOS_PROHIBITED,
  15. * UIBlurEffectStyleRegular NS_ENUM_AVAILABLE_IOS(10_0), // Adapts to user interface style
  16. * UIBlurEffectStyleProminent NS_ENUM_AVAILABLE_IOS(10_0), // Adapts to user interface style
  17. */
  18. - (void)frostedGlassViewStyle {
  19. // 实现模糊效果
  20. UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  21. // 毛玻璃视图
  22. UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];;
  23. effectView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200);
  24. [self.backImageView addSubview:effectView];
  25. [self gradientView:effectView];
  26. }
  27. - (void)gradientView:(UIView *)theView {
  28. CAGradientLayer *gradient = [CAGradientLayer layer];
  29. gradient.frame = theView.bounds;
  30. gradient.colors = [NSMutableArray arrayWithObjects:
  31. (id)[UIColor clearColor].CGColor,
  32. (id)[UIColor whiteColor].CGColor,
  33. (id)[UIColor whiteColor].CGColor,
  34. (id)[UIColor whiteColor].CGColor,
  35. (id)[UIColor whiteColor].CGColor,
  36. nil];
  37. //(0,0)表示从左上角开始变化。默认值是(0.5,0.0)表示从x轴为中间,y为顶端的开始变化
  38. gradient.startPoint = CGPointMake(0.5, 0.5);
  39. //(1,1)表示到右下角变化结束。默认值是(0.5,1.0)表示从x轴为中间,y为低端的结束变化
  40. gradient.endPoint = CGPointMake(0.5, 1.0);
  41. [theView.layer insertSublayer:gradient atIndex:0];
  42. }
  43. @end

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/419065
推荐阅读
相关标签
  

闽ICP备14008679号