Connect with us


Glur – Progressive blurs in SwiftUI

A SwiftUI library that uses Metal to display efficient progressive blurs, just like the ones used by Apple.

Glur Installation

This repository is a Swift package, so just include it in your Xcode project and target under File > Add package dependencies. Then, import Glur to the Swift files where you’ll be using it.

Glur Usage

You can add a glur effect with the following modifier:


Here are all optional parameters:

.glur(offset: 0.3, // The offset until the blur starts being applied, relative to the size of the view
      interpolation: 0.4, // The interpolation until the blur reaches its full radius, relative to the size of the view
      radius: 8.0, // The full radius of the blur once it has interpolated
      direction: .down // The direction of the blur

How it’s done

This project makes use of Apple’s new simplified Shader API for SwiftUI. I first coded a Metal shader that produces a gaussian blur for the modified view with the correct gaussian weights distribution, efficiently. Then, I modified it to vary the blur radius over the vertical or horizontal axis given the offset and interpolation values.

Given that the shader is applied through Apple’s own Shader API for SwiftUI, it’s restricted by the limitations imposed by that API. This means that it can only be applied to pure SwiftUI views, excluding UIKit-backed views, such as ScrollView.

Glur on GitHub:
Platform: iOS
⭐️: 820