简体   繁体   English

如何使 swiftUI 中的文本背景模糊

[英]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.我想模糊文本背景而不是阴影。

You can use material with a background modifier.您可以使用带有background修饰符的material

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

You can also apply blur modifier on Rectangle which you can set as background of your Text .您还可以在Rectangle上应用blur修改器,您可以将其设置为Textbackground

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM