iOS 8系统自带毛玻璃效果实现

实现毛玻璃效果主要涉及到三个类:UIBlurEffect、UIVibrancyEffect、UIVisualEffectView.

UIBlurEffect设置模糊情况的,而且系统提供了三种样式:

 UIBlurEffectStyleExtraLight,

 UIBlurEffectStyleLight,

 UIBlurEffectStyleDark


代码实现:

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    //添加背景图

    self.view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"1.jpg"]];

    

    //毛玻璃效果1,系统的

    //UIBlurEffect主要设置模糊样式

    UIBlurEffect * blurEffect=[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

    UIVisualEffectView * blureffectView=[[UIVisualEffectView alloc]initWithEffect:blurEffect];

    blureffectView.frame=CGRectMake(10, 74, 300, 300);

    [self.view addSubview:blureffectView];

    

    UIVibrancyEffect * vibrancyEffect=[UIVibrancyEffect effectForBlurEffect:blurEffect];

    UIVisualEffectView * vibrancyEffectView=[[UIVisualEffectView alloc]initWithEffect:vibrancyEffect];

    vibrancyEffectView.frame=CGRectMake(10, 74, 300, 300);

    

    UILabel * lable=[[UILabel alloc]initWithFrame:CGRectMake(100, 125, 100, 50)];

    lable.text=@"哎呀呀";

    lable.font=[UIFont systemFontOfSize:18];

    lable.textColor=[UIColor magentaColor];//此时这里的颜色设置是没有用的,因为受到了UIVibrancyEffect设置的影响

    //使lable上的显示内容会受到vibrancyEffectView颜色调节效果的影响

    [vibrancyEffectView.contentView addSubview:lable];

    [blureffectView.contentView addSubview:vibrancyEffectView];

    

    //毛玻璃效果2,系统的

    UILabel * lable2=[[UILabel alloc]initWithFrame:CGRectMake(100, 125, 100, 50)];

    lable2.text=@"哎呀呀";

    lable2.font=[UIFont systemFontOfSize:18];

    lable2.textColor=[UIColor magentaColor];//因为没有设置UIVibrancyEffect,所以此时的颜色设置是有效的

    

    UIBlurEffect * blurEffect2=[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];

    UIVisualEffectView * blureffectView2=[[UIVisualEffectView alloc]initWithEffect:blurEffect2];

    blureffectView2.frame=CGRectMake(100, 400, 260, 260);

    [self.view addSubview:blureffectView2];

    [blureffectView2.contentView addSubview:lable2];

    


    

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值