赞
踩
如示意图这种需求,对背景图片添加毛玻璃效果,再添加渐变颜色。
如图
实现
- #import "ViewController.h"
-
- @interface ViewController ()
-
- @property (weak, nonatomic) IBOutlet UIImageView *backImageView;
-
- @end
-
- @implementation ViewController
-
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self frostedGlassViewStyle];
- }
-
- /* NS_ENUM_AVAILABLE_IOS(8_0)
- * UIBlurEffectStyleExtraLight, // 额外亮度,(高亮风格)
- * UIBlurEffectStyleLight, // 亮风格
- * UIBlurEffectStyleDark, // 暗风格
- * UIBlurEffectStyleExtraDark __TVOS_AVAILABLE(10_0) __IOS_PROHIBITED __WATCHOS_PROHIBITED,
- * UIBlurEffectStyleRegular NS_ENUM_AVAILABLE_IOS(10_0), // Adapts to user interface style
- * UIBlurEffectStyleProminent NS_ENUM_AVAILABLE_IOS(10_0), // Adapts to user interface style
- */
- - (void)frostedGlassViewStyle {
- // 实现模糊效果
- UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
- // 毛玻璃视图
- UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];;
- effectView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200);
- [self.backImageView addSubview:effectView];
- [self gradientView:effectView];
- }
-
- - (void)gradientView:(UIView *)theView {
- CAGradientLayer *gradient = [CAGradientLayer layer];
- gradient.frame = theView.bounds;
- gradient.colors = [NSMutableArray arrayWithObjects:
- (id)[UIColor clearColor].CGColor,
- (id)[UIColor whiteColor].CGColor,
- (id)[UIColor whiteColor].CGColor,
- (id)[UIColor whiteColor].CGColor,
- (id)[UIColor whiteColor].CGColor,
- nil];
- //(0,0)表示从左上角开始变化。默认值是(0.5,0.0)表示从x轴为中间,y为顶端的开始变化
- gradient.startPoint = CGPointMake(0.5, 0.5);
- //(1,1)表示到右下角变化结束。默认值是(0.5,1.0)表示从x轴为中间,y为低端的结束变化
- gradient.endPoint = CGPointMake(0.5, 1.0);
- [theView.layer insertSublayer:gradient atIndex:0];
- }
-
- @end

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。