iOS 毛玻璃效果

上面是效果图,左边添加了毛玻璃选项,右边为没有毛玻璃时的样子.下边出代码

第一种设置图片//设置背景图片

    UIImage *image = [UIImage imageNamed:@"beautiful.jpg"];

    UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];//设置边框大小和屏幕一般大

    backgroundImage.image = image; //给bacegroundView设置图片

    [self.view addSubview:backgroundImage];

    [backgroundImage release];

 第二种设置图片(较简便,代码量也比较少,一般我用第二种比较多):

UIImageView *backgroundImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"beautiful.jpg"]];

    [self.view addSubview:backgroundImage];

    [backgroundImage release];

 二.添加毛玻璃效果

UIBlurEffect *logineffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

    UIVisualEffectView *logineffectView = [[UIVisualEffectView alloc]initWithEffect:logineffect];

    logineffectView.frame = CGRectMake(0, 0, backgroundImage.frame.size.width, backgroundImage.frame.size.height);

    [backgroundImage addSubview:logineffectView];

现在就可以实现毛玻璃效果了!!!

posted @ 2015-09-22 09:06  努力去做  阅读(249)  评论(0)    收藏  举报