利用UIToolBar做高斯模糊背景

效果图:

- (UIView *)containerBackgroundView {
    if (!_containerBackgroundView) {
        UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectZero];
        toolBar.barStyle = UIBarStyleBlack;
        toolBar.clipsToBounds = YES;
        _containerBackgroundView = toolBar;
    }
    return _containerBackgroundView;
}

也可以使用UIBlurEffect

UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurView.frame = myView.bounds;
[myView addSubview:blurView];

UIBlurEffectStyle

  • UIBlurEffectStyleExtraLight,//额外亮度,(高亮风格)

  • UIBlurEffectStyleLight,//亮风格

  • UIBlurEffectStyleDark//暗风格

UIBlurEffect 不能调节模糊半径

如果要调整模糊半径

可以对图片进行高斯模糊

-(UIImage *)convertToBlurImage:(UIImage *)image{
    CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
    [gaussianBlurFilter setDefaults];
    CIImage *inputImage = [CIImage imageWithCGImage:[image CGImage]];
    [gaussianBlurFilter setValue:inputImage forKey:kCIInputImageKey];
    [gaussianBlurFilter setValue:@5 forKey:kCIInputRadiusKey];
    CIImage *outputImage = [gaussianBlurFilter outputImage];
    CIContext *context   = [CIContext contextWithOptions:nil];
    CGImageRef cgimg     = [context createCGImage:outputImage fromRect:[inputImage extent]];  // note, use input image extent if you want it the same size, the output image extent is larger
    UIImage *convertedImage = [UIImage imageWithCGImage:cgimg];
    return convertedImage;
}

核心代码是[gaussianBlurFilter setValue:@5 forKey:kCIInputRadiusKey];

但是我测试100也没啥问题 没有测试出最大值

以上是几种高斯模糊的相关代码


文章推荐

* iOS面试题合集

文章来源于网络,如有侵权请联系小编删除

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 许多UIView的子类,如一个UIButton或一个UILabel,它们知道怎么绘制自己。迟早,你也将想要做一些自...
    shenzhenboy阅读 1,761评论 2 8
  • github排名https://github.com/trending,github搜索:https://gith...
    小米君的demo阅读 4,980评论 2 38
  • 测试的基本概念 测试是软件生存周期中十分重要的一个过程,是产品发布、提交给最终用户前的稳定化阶段。 1、 测试的分...
    金金毛阅读 2,464评论 0 1
  • 今天心里颇有些不平静。 昨晚下班听说有专家来讲课,就紧急调整了今天得公开课。早上去了又发了听课通知,第一节慧荣的英...
    雨荷_6fdb阅读 371评论 2 3

友情链接更多精彩内容