iOS 毛玻璃效果
iOS 7.0 使用UIToolbar类实现毛玻璃效果
UIImageView *bgImgView = [[UIImageView alloc] initWithFrame:self.view.bounds]; bgImgView.image = [UIImage imageNamed:@"huoying.jpg"] ; bgImgView.contentMode = UIViewContentModeScaleAspectFill; bgImgView.userInteractionEnabled = YES; [self.view addSubview:bgImgView]; UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:self.view.bounds]; toolbar.barStyle = UIBarStyleBlackTranslucent; [bgImgView addSubview:toolbar]; toolbar.alpha = 0.9;
iOS 8.0后有自带的类专门处理毛玻璃效果:
/* 毛玻璃的样式(枚举) UIBlurEffectStyleExtraLight, UIBlurEffectStyleLight, UIBlurEffectStyleDark */ UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; //毛玻璃视图 UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect]; effectView.frame = CGRectMake(0, 0, bgImgView.frame.size.width, bgImgView.frame.size.height); [bgImgView addSubview:effectView]; effectView.alpha = 0.9f;
相比 两者效果一样,毛玻璃效果还有其他实现方法(CoreImage、vImage、GPUImage)
可参考:http://www.cnblogs.com/xiaofeixiang http://www.jianshu.com/p/6dd0eab888a6
UIVisualEffectView:
UIToolbar :