
- SwiftUI - Home
- SwiftUI - Overview
- SwiftUI vs UIkit
- SwiftUI Environment
- SwiftUI - Environment Setup
- SwiftUI - Basic Components
- SwiftUI - Building First Application
- SwiftUI Views
- SwiftUI - Views
- SwiftUI - Customize Text View
- SwiftUI - Custom Image View
- SwiftUI - Stacks
- SwiftUI Drawing Shapes
- SwiftUI - Shapes
- SwiftUI - Drawing line
- SwiftUI - Drawing Rectangle
- SwiftUI - Drawing Rounded Rectangle
- SwiftUI - Drawing Triangle
- SwiftUI - Drawing Circle
- SwiftUI - Drawing Star
- SwiftUI - Drawing Polygon
- SwiftUI - Drawing Pie chart
- SwiftUI - Using built-in shapes
- SwiftUI - Text
- SwiftUI - Text View
- SwiftUI - Text Input and Output
- SwiftUI - Color
- SwiftUI - Color
- SwiftUI - Colorpicker
- SwiftUI - Gradients
- SwiftUI - Adjust Color
- SwiftUI - Effects
- SwiftUI - Effects
- SwiftUI - Blend Effect
- SwiftUI - BLur Effect
- SwiftUI - Shadow Effect
- SwiftUI - Hover Effect
- SwiftUI - Animations
- SwiftUI - Animations
- SwiftUI - Creating Animations
- SwiftUI - Creating an Explicit Animation
- SwiftUI - Multiple Animations
- SwiftUI - Transitions
- SwiftUI - Asymmetric Transition
- SwiftUI - Custom Transition
- SwiftUI - Image
- SwiftUI - Images
- SwiftUI - Image as Background
- SwiftUI - Rotating Image
- SwiftUI - Media
- SwiftUI - View Layout
- SwiftUI - View Layout
- SwiftUI - View Size
- SwiftUI - View Spacing
- SwiftUI - View Padding
- SwiftUI - UI Controls
- SwiftUI - UI Controls
- SwiftUI - Button
- SwiftUI - CheckBox
- SwiftUI - Menubar
- SwiftUI - Toolbar
- SwiftUI - Search Bar
- SwiftUI - TextField
- SwiftUI - Slider
- SwiftUI - Toggle
- SwiftUI - Pickers
- SwiftUI - Menus
- SwiftUI - List & Tables
- SwiftUI - Lists
- SwiftUI - Static List
- SwiftUI - Dynamic List
- SwiftUI - Customize List
- SwiftUI - Tables
- SwiftUI - Forms
- SwiftUI - Forms
- SwiftUI - Breaking Forms in Sections
- SwiftUI - Event Handling
- SwiftUI - Event Handling
- SwiftUI - Gesture
- SwiftUI - Clipboard
- SwiftUI - Drag and Drop
- SwiftUI - Focus
- SwiftUI - Alert
- SwiftUI - Miscellaneous
- SwiftUI - Containers
- SwiftUI - Navigation
- SwiftUI - Notifications
- SwiftUI - Cross-Platform UI
- SwiftUI - Data
- SwiftUI - Accessibility
- SwiftUI - Framework Integration
- SwiftUI - Framework Integration
- SwiftUI - Interfacing with UIKit
- SwiftUI - Creating macOS App
- SwiftUI Useful Resources
- SwiftUI - Useful Resources
- SwiftUI - Discussion
SwiftUI - Blur Effect
The Blur effect in SwiftUI applies a blurring filter on the user interface's specified view, background, or image. It is commonly used to enhance the visual experience, creating depth, focusing on the specified components or improve the app's user experience.
SwiftUI supported the Gaussian blur filter, which is a blurring type of filter which uses a mathematical function known as the Gaussian function. It creates a blur effect by smoothing the image by averaging the pixels in the given radius. In SwiftUI, we can achieve a blur effect using the following ways −
- blur() Modifier
- Material Type
The blur() Modifier
SwiftUI provides an in-built modifier named blur() to achieve a blur effect. This modifier allows us to add a custom Gaussian blur effect to any view instantly. It is commonly used to blur the background to enhance the foreground components.
Syntax
Following is the syntax −
func blur(radius: CGFloat, opaque: Bool = false)->some View
Parameters
This modifier takes the following parameters −
- radius: It represents the radial size of the blur.
- opaque: If the value of this parameter is true, then we are allowed to create an opaque blur. Otherwise, we are only allowed for transparency. It is an optional parameter.
Example
The following SwiftUI program is used to blur an image view.
import SwiftUI struct ContentView: View { var body: some View { VStack{ Text("Original Image:").font(.largeTitle) Image("wallpaper").resizable() .frame(width: 300, height: 300) Text("Blurred Image:").font(.largeTitle) Image("wallpaper") .resizable() .frame(width: 300, height: 300) .blur(radius: 4.5) } } } #Preview { ContentView() }
Output

Material Type
Apart from the blur() modifier SwiftUI provides us with another method to create a blur effect that is Material type. The Material type is a collection of pre-defined blur effects with different levels of translucency effect. Using these we can achieve a feeling of depth.
They allow us to blur the background without affecting the foreground elements. They are not view but they will create a translucent layer between the view and its background. They are defined in Human InterfaceGuidelines. Material types are commonly used with background () or overlay() modifiers.
SwiftUI supports the following type of Material types −
- .regularMaterial: It is used to apply the regular material effect.
- .thinMaterial: It is used to apply the lighter material effect.
- .ultraThinMaterial: It is used to apply the lightest material effect.
- .thickMaterial: It is used to apply a thicker material effect.
- .ultraThickMaterial: It is used to apply a thickest material effect.
- .bar: It is used to apply suitable material effects for bars and toolbars.
Syntax
Following is the syntax −
.backgound(.thinMaterial)
Example
The Following SwiftUI program is used to blur the current view using Material Type.
import SwiftUI struct ContentView: View { var body: some View { ZStack { Rectangle().fill(.mint) VStack{ Text("Thin Material") Rectangle() .frame(width: 250, height: 100) .background(.thinMaterial) Text("Thick Material") Rectangle() .frame(width: 250, height: 100) .background(.thickMaterial) Text("Ultra Thin Material") Rectangle() .frame(width: 250, height: 100) .background(.ultraThinMaterial) Text("Thick Material") Rectangle() .frame(width: 250, height: 100) .background(.ultraThickMaterial) Text("Regular Material") Rectangle() .frame(width: 250, height: 100) .background(.regularMaterial) } } } } #Preview { ContentView() }
Output
