[英]How to achieve ios blur background with roundedrectangle()?
I have this code:我有这个代码:
import SwiftUI
struct MyBackGround: View {
var body: some View {
ZStack() {
Color.pink.ignoresSafeArea()
RoundedRectangle(cornerRadius: 20).background(Color.white.opacity(0.5))
.frame(width: 220, height: 100)
}
}
}
I want to achieve the similar look of iOS blur background, but it did not work.我想实现类似 iOS 模糊背景的外观,但没有奏效。
You can achieve this with a simpler code.您可以使用更简单的代码来实现这一点。 Your code does not work because your
RoundedRectangle
contains black as its foreground
color originally.您的代码不起作用,因为您的
RoundedRectangle
最初包含黑色作为其foreground
。
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack {
Color.pink.ignoresSafeArea(.all)
RoundedRectangle(cornerRadius: 20)
.fill(.ultraThinMaterial)
.frame(width: 200, height: 200)
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.