簡體   English   中英

如何使用roundedrectangle() 實現ios 模糊背景?

[英]How to achieve ios blur background with roundedrectangle()?

我有這個代碼:

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)
        }
    }
}

而這張圖片: 模糊圖像背景

我想實現類似 iOS 模糊背景的外觀,但沒有奏效。

您可以使用更簡單的代碼來實現這一點。 您的代碼不起作用,因為您的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM