當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Swift Optional tint(_:)用法及代碼示例

實例方法

tint(_:)

設置此視圖中的色調顏色。

聲明

func tint(_ tint: Color?) -> some View

參數

tint

要應用的色調Color

詳述

使用此方法覆蓋此視圖的默認強調色。與可以被用戶偏好覆蓋的應用程序的強調色不同,色調始終受到尊重,並且應該用作為控件提供額外含義的一種方式。

此示例分別顯示帶有 ShapeStyle/greenShapeStyle/red 色調顏色的應答和拒絕按鈕。


struct ControlTint: View {
    var body: some View {
        HStack {
            Button {
                // Answer the call
            } label: {
                Label("Answer", systemImage: "phone")
            }
            .tint(.green)
            Button {
                // Decline the call
            } label: {
                Label("Decline", systemImage: "phone.down")
            }
            .tint(.red)
        }
        .padding()
    }
}

可用版本

iOS 15.0+, iPadOS 15.0+, macOS 12.0+, Mac Catalyst 15.0+, tvOS 15.0+, watchOS 8.0+

相關用法


注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Optional tint(_:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。