首页 > 代码库 > ios毛玻璃效果
ios毛玻璃效果
方法一:支持所有ios系统版本:
- (void)setupBlurView
{
UIImageView *darkView = [[UIImageView alloc] init];
darkView.frame = self.view.bounds;
UIImage *image = [UIImage imageWithData:_hotModel.picData];
darkView.image = image;
darkView.backgroundColor = [UIColor clearColor];
[self.view addSubview:darkView];
_darkView = darkView;
UIToolbar *toolBar = [[UIToolbar alloc] init];
[toolBar setBarStyle:UIBarStyleBlack];
[darkView addSubview:toolBar];
toolBar.translatesAutoresizingMaskIntoConstraints = NO;
[toolBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(darkView);
}];
}
方法二:只能在ios8.0以上才有效果,利用系统的api实现的
- (void)addEffectView{
UIImageView *darkView = [[UIImageView alloc] init];
darkView.frame = self.view.bounds;
UIImage *image = [UIImage imageWithData:_hotModel.picData];
darkView.image = image;
darkView.backgroundColor = [UIColor clearColor];
[self.view addSubview:darkView];
_darkView = darkView;
UIBlurEffect *dark = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:dark];
effectView.frame = self.view.bounds;
[darkView addSubview:effectView];
}
效果图:
ios毛玻璃效果