[英]How can I make a background in SwiftUI translucent?
How can I make the text background above the navigation bar translucent so that it looks like the text and navigation bar are the same object?如何使导航栏上方的文本背景为半透明,使文本和导航栏看起来像 object?
VStack(spacing: 0) {
Text("Test")
.padding(.top, 9.5)
.padding(.bottom, 8)
.frame(minWidth: 0, maxWidth: .infinity)
.background(Color.gray) // I used a custom color set in the screenshot
.font(.footnote)
NavigationView {
List {
Text("Name")
Text("Name")
Text("Name")
} .listStyle(GroupedListStyle())
.navigationBarTitle(Text(""), displayMode: .inline)
.navigationBarBackButtonHidden(true)
.navigationBarItems(
leading:
Button("Cancel") {
// self.presentationMode.wrappedValue.dismiss()
},
trailing:
Button("Done") {
}.disabled(true)
)
}
}
SwiftUI's Color
has an opacity()
function that returns another Color
with the given opacity. SwiftUI 的
Color
有一个opacity()
function 返回另一个具有给定不透明度的Color
。 An opacity of 1.0 would be the same color, while an opacity of 0.0 would be completely clear.不透明度 1.0 将是相同的颜色,而不透明度 0.0 将完全清晰。
For example, if you wanted to have the color be between completely opaque and completely clear, change:例如,如果您想让颜色介于完全不透明和完全透明之间,请更改:
Text("Test")
.padding(.top, 9.5)
.padding(.bottom, 8)
.frame(minWidth: 0, maxWidth: .infinity)
.background(Color.gray)
.font(.footnote)
To:至:
Text("Test")
.padding(.top, 9.5)
.padding(.bottom, 8)
.frame(minWidth: 0, maxWidth: .infinity)
.background(Color.gray.opacity(0.5)) //Here is where we use the opacity
.font(.footnote)
Source: https://developer.apple.com/documentation/swiftui/color资料来源: https://developer.apple.com/documentation/swiftui/color
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.