IOS-frosted glass effect

Source: Internet
Author: User

   IOS-frosted glass effect

After iOS8 Apple provides an API for making frosted glass effects

This is the Uivisualeffectview, with this initwitheffect: to initialize, and then, he has two effects inherited from Uivisualeffect. This parent does not care, do nothing, mainly see his two sub-class Uiblureffect and Uivibrancyeffect.

Uiblureffect: This is the one that affects the rear view of the frosted glass

Uivibrancyeffect: This is the view that affects the frosted glass.

is not very beautiful, it is not difficult to do it.

First say the effect of the hair glass under the practice.

You first initialize a Uiblureffect object, he has three styles

typedef ns_enum (Nsinteger, Uiblureffectstyle) {

Uiblureffectstyleextralight,

Uiblureffectstylelight,

Uiblureffectstyledark

}

The above effects are all made out of uiblureffectstylelight.

The Uiblureffectstyleextralight effect is as follows

The Uiblureffectstyledark effect is as follows

And then we create a Uivisualeffectview object with this Uiblureffect object. Add this Uivisualeffectview object as a child view with the view you need to be virtualized.

And then say the effect on the frosted glass.

Create a Uivibrancyeffect object, initialize it with the previously created Blur, and then create a Uivisualeffectview object, initialized with this Uivibrancyeffect object, Finally, add the sub-view you want to add to Uivisualeffectview's Contentview.

The complete code is as follows:

// UIBlurEffect效果UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];imageView.image = [UIImage imageNamed:@"pic"];UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];UIVisualEffectView *ev = [[UIVisualEffectView alloc] initWithEffect:blur];ev.frame = self.view.frame;[imageView addSubview:ev];// UIVibrancyEffect效果UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blur];UIVisualEffectView *ano = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];ano.frame = self.view.frame;UILabel *label = [[UILabel alloc] init];label.font = [UIFont systemFontOfSize:40];label.frame = CGRectMake(100, 100, 400, 100);label.text = @"Beautiful View";[ev.contentView addSubview:ano];[ano.contentView addSubview:label];[self.view addSubview:imageView];

IOS-frosted glass effect

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.