有的時候我們在開發(fā)過程中為了增加些視覺效果,提高用戶與界面的溝通,我們想把背景圖片加一點特效.所以就可以用到毛玻璃特效
代碼如下
//創(chuàng)建背景圖片
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];
//創(chuàng)建UILabel
UILabel*viLabel = [[UILabelalloc]initWithFrame:CGRectMake(30,200,self.view.frame.size.width-60,200)];
viLabel.text=@"生活不止眼前的茍且";
viLabel.font= [UIFontsystemFontOfSize:30];
/**創(chuàng)建UIBlurEffect類的對象*/
UIBlurEffect*blu = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleLight];
/**創(chuàng)建UIVibrancyEffect類的對象*/
UIVibrancyEffect*vibrancy = [UIVibrancyEffecteffectForBlurEffect:blu];
/**創(chuàng)建UIVisuaIEffectView類的對象,并以vibrancy為參數(shù)*/
UIVisualEffectView*visual = [[UIVisualEffectViewalloc]initWithEffect:vibrancy];
/*毛玻璃的效果*/
visual.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
/*設(shè)置透明度.(越趨近于零的時候文字效果越不明顯)*/
visual.alpha=1;
/*將文字賦到毛玻璃視覺效果上*/
[visual.contentViewaddSubview:viLabel];
/*將毛玻璃效果賦到背景圖片上*/
[vibrancyImageViewaddSubview:visual];
[visualrelease];