In a SwiftUI List
, when a row is selected, a blue selection is drawn in the selection, and foreground Text
with the default primary
color is automatically made white. 對于具有自定義顏色的其他視圖,我希望能夠確保它們變成白色以匹配系統應用程式。例如,查看所選行上的藍點:
示例代碼:
List(selection: $selection) {
ForEach(0..<4) { index in
HStack {
Image(systemName: "circle.fill")
.foregroundColor(.blue)
Text("Test")
}
.tag(index)
}
}
關于如何在這里獲得正確結果的任何提示???
有了NSTableCellView
,就有了這個backgroundStyle
屬性,但我找不到這樣的東西。
- 我搜索了所有可用的環境變數,但找不到任何合適的。
- 我也嘗試過手動
isSelected
在每一行的視圖上包含一個系結,但是選擇系結List
在滑鼠向上之前不會更新,而突出顯示在滑鼠向下和拖動時會更新,因此這會導致外觀閃爍而不是也對。
我還希望不僅自定義單個 SF Symbol 影像,而且還RoundedRectangle
希望自定義一個使用自定義前景色繪制的影像,我希望在選擇時將其變為白色。
uj5u.com熱心網友回復:
方法
- 為單元格使用標簽
代碼
struct ContentView: View {
@State private var selection: Int?
var body: some View {
List(selection: $selection) {
ForEach(0..<4) { index in
Label("Test", systemImage: "circle.fill")
.tag(index)
}
}
}
}
截屏
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/528931.html