Sitemap
Jakir Hossain

Jakir Hossain⁠

Programmer | Explorer | Reader | Writer

Member-only story

Obscures Scrollable Content in SwiftUI

2 min readMay 4, 2025

--

If you want to obscure some content in your app for free users, you can do it using ZStack.

Here is a simple and clean SwiftUI UI that obscures content and shows a “Buy Now” button if the IAP is not purchased.

import SwiftUI

struct ContentView: View {

@State var isPro = false

var body: some View {
ZStack {
ScrollView {
VStack(spacing: 20) {
ForEach(0..<20, id: \.self) { i in
Text("Premium Content Item \(i)")
.font(.title3)
.padding()
.frame(maxWidth: .infinity)
.background(Color(.secondarySystemBackground))
.cornerRadius(12)
.padding(.horizontal)
}
}
.padding(.top, 20)
}
.blur(radius: isPro ? 0 : 5)


if !isPro {
Color.black.opacity(0.5)
.ignoresSafeArea()
.allowsHitTesting(false) // this will enable scroll


VStack(spacing: 16) {
Text("Unlock Full Access 🔓")
.font(.title2)
.bold()
.foregroundColor(.white)

Button(action: {
isPro.toggle()
print("Purchase")
}) {…

--

--

Jakir Hossain
Jakir Hossain

Written by Jakir Hossain⁠

Programmer | Explorer | Reader | Writer