有的时候我们在开发过程中为了增加些视觉效果,提高用户与界面的沟通,我们想把背景图片加一点特效.所以就可以用到毛玻璃特效
代码如下
//创建背景图片
UIImageView*vibrancyImageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
UIImage*image2 = [UIImageimageNamed:@"6_1.jpg"];
[image2imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
vibrancyImageView.image= image2;
[self.viewaddSubview:vibrancyImageView];
[vibrancyImageViewrelease];
//创建UILabel
UILabel*viLabel = [[UILabelalloc]initWithFrame:CGRectMake(30,200,self.view.frame.size.width-60,200)];
viLabel.text=@"生活不止眼前的苟且";
viLabel.font= [UIFontsystemFontOfSize:30];
/**创建UIBlurEffect类的对象*/
UIBlurEffect*blu = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight];
/**创建UIVibrancyEffect类的对象*/
UIVibrancyEffect*vibrancy = [UIVibrancyEffecteffectForBlurEffect:blu];
/**创建UIVisuaIEffectView类的对象,并以vibrancy为参数*/
UIVisualEffectView*visual = [[UIVisualEffectViewalloc]initWithEffect:vibrancy];
/*毛玻璃的效果*/
visual.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
/*设置透明度.(越趋近于零的时候文字效果越不明显)*/
visual.alpha=1;
/*将文字赋到毛玻璃视觉效果上*/
[visual.contentViewaddSubview:viLabel];
/*将毛玻璃效果赋到背景图片上*/
[vibrancyImageViewaddSubview:visual];
[visualrelease];