實例方法
color
colorInvert()
反轉此視圖中的顏色。
聲明
func colorInvert() -> some View
返回值
反轉其顏色的視圖。
詳述
colorInvert()
修飾符反轉視圖中的所有顏色,以便每種顏色顯示為其補色。例如,藍色轉換為黃色,白色轉換為黑色。
在下麵的示例中,兩個紅色方塊各有一個內部綠色圓圈。倒置的正方形顯示了正方形顏色的效果:紅色和綠色的互補色——藍綠色和紫色。
struct InnerCircleView: View {
var body: some View {
Circle()
.fill(Color.green)
.frame(width: 40, height: 40, alignment: .center)
}
}
struct ColorInvert: View {
var body: some View {
HStack {
Color.red.frame(width: 100, height: 100, alignment: .center)
.overlay(InnerCircleView(), alignment: .center)
.overlay(Text("Normal")
.font(.callout),
alignment: .bottom)
.border(Color.gray)
Spacer()
Color.red.frame(width: 100, height: 100, alignment: .center)
.overlay(InnerCircleView(), alignment: .center)
.colorInvert()
.overlay(Text("Inverted")
.font(.callout),
alignment: .bottom)
.border(Color.gray)
}
.padding(50)
}
}
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Never colorMultiply(_:)用法及代碼示例
- Swift Never confirmationDialog(_:isPresented:titleVisibility:actions:)用法及代碼示例
- Swift Never compositingGroup()用法及代碼示例
- Swift Never contextMenu(menuItems:)用法及代碼示例
- Swift Never cornerRadius(_:antialiased:)用法及代碼示例
- Swift Never contentShape(_:_:eoFill:)用法及代碼示例
- Swift Never coordinateSpace(name:)用法及代碼示例
- Swift Never contrast(_:)用法及代碼示例
- Swift Never controlSize(_:)用法及代碼示例
- Swift Never confirmationDialog(_:isPresented:titleVisibility:actions:message:)用法及代碼示例
- Swift Never confirmationDialog(_:isPresented:titleVisibility:presenting:actions:message:)用法及代碼示例
- Swift Never containerShape(_:)用法及代碼示例
- Swift Never confirmationDialog(_:isPresented:titleVisibility:presenting:actions:)用法及代碼示例
- Swift Never clipShape(_:style:)用法及代碼示例
- Swift Never clipped(antialiased:)用法及代碼示例
- Swift Never pageCommand(value:in:step:)用法及代碼示例
- Swift Never opacity(_:)用法及代碼示例
- Swift Never accessibilityAction(action:label:)用法及代碼示例
- Swift Never alert(isPresented:error:actions:message:)用法及代碼示例
- Swift Never flipsForRightToLeftLayoutDirection(_:)用法及代碼示例
- Swift Never position(x:y:)用法及代碼示例
- Swift Never position(_:)用法及代碼示例
- Swift Never luminanceToAlpha()用法及代碼示例
- Swift Never accessibilityAction(_:_:)用法及代碼示例
- Swift Never previewDisplayName(_:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Never colorInvert()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。