Three ways to achieve the effect of a frosted glass in iOS

Source: Internet
Author: User
Tags deprecated

Way one: Uitoolbar to achieve the effect of frosted glass

Before iOS7.0 (including) or a system class can achieve the effect of the glass, is Uitoolbar this class, and use is quite simple, a few lines of code can be done.

 1  /*2 style of frosted glass (enumeration) 3 Uibarstyledefault = 0, 4 uibarstyleblack = 1, 5 Uibarstyleblac Kopaque = 1,//Deprecated. Use Uibarstyleblack 6 uibarstyleblacktranslucent = 2,//Deprecated. Use Uibarstyleblack and set the translucent property to YES 7*/ 8Uiimageview *bgimgview =[[Uiimageview alloc] initWithFrame:self.view.bounds];9Bgimgview.image = [UIImage imagenamed:@"huoying4.jpg"];Ten[Self.view Addsubview:bgimgview]; One      AUitoolbar *toolbar = [[Uitoolbar alloc] Initwithframe:cgrectmake (0,0, bgimgview.frame.size.width*0.5, BgImgView.frame.size.height)]; -Toolbar.barstyle =uibarstyleblacktranslucent; -[Bgimgview Addsubview:toolbar];

way Two: uiblureffect for frosted glass effects

after iOS8.0, Apple added a class Uivisualeffectview, which achieves the same effect as the uitoolbar above, and is also very efficient and very simple to use. , a few lines of code.  uivisualeffectview is an abstract class that cannot be used directly, and is implemented through the following three subclasses (Uiblureffect, Uivisualeffevt, Uivisualeffectview).

Subclass Uiblureffect has only one class method for quickly creating a frosted glass effect, and the parameter is an enumeration used to set the style of the frosted glass.

 1Uiimageview *bgimgview =[[Uiimageview alloc] initWithFrame:self.view.bounds];2Bgimgview.image = [UIImage imagenamed:@"huoying4.jpg"]; 3Bgimgview.contentmode =Uiviewcontentmodescaleaspectfill;4     //[Bgimgview setimagetoblur: [UIImage imagenamed:@ "huoying4.jpg"] blurradius:20 Completionblock:nil]; 5bgimgview.userinteractionenabled =YES;6[Self.view Addsubview:bgimgview];7      8     /*9 style of frosted glass (enumeration) uiblureffectstyleextralight,11 uiblureffectstylelight,12 UIBlurEffectStyleDark13 */ -Uiblureffect *effect =[Uiblureffect Effectwithstyle:uiblureffectstyledark]; theUivisualeffectview *effectview =[[Uivisualeffectview alloc] initwitheffect:effect]; -Effectview.frame = CGRectMake (0,0, bgimgview.frame.size.width*0.5, bgImgView.frame.size.height); -[Bgimgview Addsubview:effectview];

way three: Gaussian fuzzy processing to achieve the glass effect

This method is my preferred method, the use of Gaussian blur processing can easily make the glass effect.

1Uiimageview *bgimgview =[[Uiimageview alloc] initWithFrame:self.view.bounds];2   //bgimgview.image = [UIImage imagenamed:@ "huoying4.jpg"];3Bgimgview.contentmode =Uiviewcontentmodescaleaspectfill;4   //to the background image of the glass effect processing parameters Blurradius default is 20, can be specified, the last parameter block callback can be nil5[Bgimgview setimagetoblur: [UIImage imagenamed:@"huoying4.jpg"] Blurradius: -Completionblock:nil];6bgimgview.userinteractionenabled =YES;7[Self.view Addsubview:bgimgview];

Three ways to achieve the effect of a frosted glass in iOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.