You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SwiftUI界面问题:如何去除VStack圆角区域上的白色方形背景

如何去除圆角VStack上的白色方形背景?

从下方UI可以看到,带有圆角的VStack上叠加了一块白色方形背景,需要移除这个背景:

带有白色方形背景的圆角VStack UI

原SwiftUI代码:

import SwiftUI

struct PresenzeUiView: View {
    @Binding var users: [UserTable]
    @State private var progressbarui = 20.0
    @State private var dettaglioPresenzaShow = false
    
    func getDate() -> String {
        let MyFormatter = DateFormatter()
        MyFormatter.dateFormat = "dd/MM/YYYY"
        var date = MyFormatter.string(from: Date())
        return "" + date
    }
    
    var body: some View {
        VStack {
            VStack(alignment: .leading) {
                Text("Oggi").multilineTextAlignment(.leading).colorInvert()
                    .font(.title2)
                    .fixedSize()
                Text(getDate())
                    .multilineTextAlignment(.leading).colorInvert()
                    .font(.subheadline)
                    .fixedSize()
                
                Text("Personale non in attività")
                    .multilineTextAlignment(.leading).colorInvert()
                    .font(.subheadline)
                    .fixedSize().padding(.top, 10)
                
                ProgressView("", value: progressbarui, total: 100).accentColor(Color.red).frame(height: 80)
                
            }.frame(width: 250).cornerRadius(20)
                .padding()
                .overlay(
                    RoundedRectangle(cornerRadius: 20)
                        .stroke(.white, lineWidth: 5)
                )
            
        }.background(Color.white).frame(width: UIScreen.screenWidth - 300, height: UIScreen.screenHeight)
    }
}

解决方法:

这个白色方形背景是最外层VStack通过.background(Color.white)设置的,直接删除该修饰符即可移除白色背景。

修改后的完整代码:

import SwiftUI

struct PresenzeUiView: View {
    @Binding var users: [UserTable]
    @State private var progressbarui = 20.0
    @State private var dettaglioPresenzaShow = false
    
    func getDate() -> String {
        let MyFormatter = DateFormatter()
        MyFormatter.dateFormat = "dd/MM/YYYY"
        var date = MyFormatter.string(from: Date())
        return "" + date
    }
    
    var body: some View {
        VStack {
            VStack(alignment: .leading) {
                Text("Oggi").multilineTextAlignment(.leading).colorInvert()
                    .font(.title2)
                    .fixedSize()
                Text(getDate())
                    .multilineTextAlignment(.leading).colorInvert()
                    .font(.subheadline)
                    .fixedSize()
                
                Text("Personale non in attività")
                    .multilineTextAlignment(.leading).colorInvert()
                    .font(.subheadline)
                    .fixedSize().padding(.top, 10)
                
                ProgressView("", value: progressbarui, total: 100).accentColor(Color.red).frame(height: 80)
                
            }.frame(width: 250).cornerRadius(20)
                .padding()
                .overlay(
                    RoundedRectangle(cornerRadius: 20)
                        .stroke(.white, lineWidth: 5)
                )
            
        }.frame(width: UIScreen.screenWidth - 300, height: UIScreen.screenHeight)
    }
}

内容的提问来源于stack exchange,提问作者riki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 09:25:34