SwiftUI界面问题:如何去除VStack圆角区域上的白色方形背景
如何去除圆角VStack上的白色方形背景?
从下方UI可以看到,带有圆角的VStack上叠加了一块白色方形背景,需要移除这个背景:

原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
相关产品推荐
相关产品推荐

