實例方法
opacity(_:)
設置此視圖的透明度。
聲明
func opacity(_ opacity: Double) -> some View
返回值
設置此視圖透明度的視圖。
參數
opacity
介於 0(完全透明)和 1(完全不透明)之間的值。
詳述
應用不透明度來顯示位於另一個視圖或 de-emphasize 視圖後麵的視圖。
將opacity(_:)
修改器應用於已經對其不透明度進行轉換的視圖時,修改器會增加底層不透明度轉換的效果。
下麵的示例顯示了配置為重疊的黃色和紅色矩形。頂部黃色矩形的不透明度設置為 50%,允許底部矩形的被遮擋部分可見:
struct Opacity: View {
var body: some View {
VStack {
Color.yellow.frame(width: 100, height: 100, alignment: .center)
.zIndex(1)
.opacity(0.5)
Color.red.frame(width: 100, height: 100, alignment: .center)
.padding(-40)
}
}
}
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Never onTapGesture(count:perform:)用法及代碼示例
- Swift Never overlay(_:in:fillStyle:)用法及代碼示例
- Swift Never onSubmit(of:_:)用法及代碼示例
- Swift Never onChange(of:perform:)用法及代碼示例
- Swift Never offset(x:y:)用法及代碼示例
- Swift Never overlay(_:ignoresSafeAreaEdges:)用法及代碼示例
- Swift Never overlay(alignment:content:)用法及代碼示例
- Swift Never offset(_:)用法及代碼示例
- Swift Never pageCommand(value:in:step:)用法及代碼示例
- Swift Never colorMultiply(_:)用法及代碼示例
- Swift Never accessibilityAction(action:label:)用法及代碼示例
- Swift Never alert(isPresented:error:actions:message:)用法及代碼示例
- Swift Never confirmationDialog(_:isPresented:titleVisibility:actions:)用法及代碼示例
- Swift Never flipsForRightToLeftLayoutDirection(_:)用法及代碼示例
- Swift Never position(x:y:)用法及代碼示例
- Swift Never position(_:)用法及代碼示例
- Swift Never luminanceToAlpha()用法及代碼示例
- Swift Never accessibilityAction(_:_:)用法及代碼示例
- Swift Never previewDisplayName(_:)用法及代碼示例
- Swift Never badge(_:)用法及代碼示例
- Swift Never progressViewStyle(_:)用法及代碼示例
- Swift Never buttonStyle(_:)用法及代碼示例
- Swift Never popover(isPresented:attachmentAnchor:arrowEdge:content:)用法及代碼示例
- Swift Never projectionEffect(_:)用法及代碼示例
- Swift Never background(_:ignoresSafeAreaEdges:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Never opacity(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。