美文网首页iOS 常见问题汇总
UIVisualEffectView的三种样式

UIVisualEffectView的三种样式

作者: 枣哥 | 来源:发表于2016-10-29 11:47 被阅读473次

UIVisualEffectView就是大家常说的毛玻璃,我简单的介绍一下他的三种样式:

1.UIBlurEffectStyleDark

Dark.png

2.UIBlurEffectStyleExtraLight

ExtraLight.png

3.UIBlurEffectStyleLight

Light.png

以上是这三种样式呈现出的界面,个人感觉还是第三种(UIBlurEffectStyleLight)的效果比较好!

下面上一下代码:

#pragma mark-->快速创建UIVisualEffectView的方法
- (void)setupUIVisualEffectViewStyle:(UIBlurEffectStyle)style andSize:(CGRect)rect {

UIVisualEffectView *visualEffect = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:style]];

visualEffect.frame = rect;

[self.view addSubview:visualEffect];

UIImageView *ima = [[UIImageView alloc]init];

ima.image = [UIImage imageNamed:@"hjgh8"];

ima.center = CGPointMake(visualEffect.bounds.size.width/2, visualEffect.bounds.size.height/2);

ima.bounds = CGRectMake(0, 0, 100, 50);

[visualEffect addSubview:ima];

}
- (void)viewDidLoad {
    [super viewDidLoad];

    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hjgh8"]];
   
    [self.view addSubview:image];

    image.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);

    //UIBlurEffectStyleDark
    [self setupUIVisualEffectViewStyle:UIBlurEffectStyleDark andSize:CGRectMake(0, 30, self.view.bounds.size.width, 100)];
   
     //UIBlurEffectStyleExtraLight
    [self setupUIVisualEffectViewStyle:UIBlurEffectStyleExtraLight andSize:CGRectMake(0, 230, self.view.bounds.size.width, 100)];
   
      //UIBlurEffectStyleLight
    [self setupUIVisualEffectViewStyle:UIBlurEffectStyleLight andSize:CGRectMake(0, 430, self.view.bounds.size.width, 100)];
    
}

希望此篇文章对大家有所帮助!

相关文章

网友评论

    本文标题:UIVisualEffectView的三种样式

    本文链接:https://www.haomeiwen.com/subject/eeqyuttx.html