asdfdfhj
asdfdfhj

Reputation: 11

How to make text background blur in swiftUI

I have multiple Quotes in scroll view in form of text and image on background and i want to make view blur only for text not full image. Here is code :-

Text(text)
.padding(.trailing, 10)
.font(.custom(AppData.shared().appFont, size: 38))
.foregroundColor(.white)
.frame(width: UIScreen.screenWidth, height: UIScreen.screenHeight)
.multilineTextAlignment(.center)
.shadow(color: .black.opacity(0.5), radius: 7)
.minimumScaleFactor(0.5)
.ignoresSafeArea()

I want to blur text background instead of shadow.

Upvotes: 1

Views: 2004

Answers (1)

Nirav D
Nirav D

Reputation: 72410

You can use material with a background modifier.

Text(text)
    .padding()
    .foregroundColor(.white)
    .background(.ultraThinMaterial)

You can also apply blur modifier on Rectangle which you can set as background of your Text.

Text(text)
    .padding()
    .foregroundColor(.white)
    .background(
         Rectangle()
            .fill(.gray.opacity(0.5))
            .blur(radius: 5)
    )

Upvotes: 4

Related Questions