Swift Gaussian blur for custom view

Source: Internet
Author: User

var bgimage = Uiimageview ()

var Backbutton = UIButton ()

var Titlelabel = UILabel ()

Let Screen_h = UIScreen.main.bounds.height

Let Screen_w = UIScreen.main.bounds.width

Override Init (Frame:cgrect) {

Super.init (Frame:frame)

Initui ()

}

Required init? (Coder Adecoder:nscoder) {

FatalError ("Init (coder:) have not been implemented")

}

Func Initui () {

Bgimage.frame=cgrect (x:0,y:0,width:screen_w,height:64)

Bgimage.backgroundcolor = Uicolor (Patternimage:uiimage (named: "NAVBAR_BG")!)

Self.addsubview (Bgimage)

First create a Blur effect

Let Blureffect = Uiblureffect (style:. Dark)

Then create a view that hosts the Blur effect

Let Blurview = Uivisualeffectview (effect:blureffect)

Set the size of the blur view (full screen)

BlurView.frame.size = Cgsize (Width:screen_w, height:64)

Add Blur view to Page view (Blur appears underneath the Blur view)

blurview.alpha=0.7

Self.addsubview (Blurview)

Backbutton = UIButton (type:. Custom)

Backbutton.frame = CGRect (x:0, y:20, width:60, height:44)

Backbutton.backgroundcolor = Uicolor.clear

Backbutton.setimage (UIImage (named: "Btn_return"), for:. Normal)

Self.addsubview (Backbutton)

Titlelabel.frame=cgrect (X:SCREEN_W/2-100,Y:20+44/2-8,WIDTH:200,HEIGHT:18)

Titlelabel.text= "Old Glass"

Titlelabel.textcolor=uicolor.white

titlelabel.textalignment =. Center

Titlelabel.font = Uifont (name: "Arial", size:16.0)

Self.addsubview (Titlelabel)

}

Swift Gaussian blur for custom view

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.