实例方法
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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。