Программируем под IOS
-
Anonymous
Почему я не могу изменить фон строки в списке в SwiftUI
Сообщение
Anonymous »
Я не понимаю, почему listRowBackground применяется только к элементам списка без дочерних элементов и не применяется к расширяемым?
Вот как это выглядит:
список
Код: Выделить всё
List(viewModel.tree, id: \.id, children: \.children) { tree in
HStack{
Image(systemName:tree.children != nil ? "folder" : "antenna.radiowaves.left.and.right")
.fontWeight(.medium)
Text(tree.name)
.fontWeight(.medium)
.textCase(.uppercase)
.padding(.vertical, 5)
}
.foregroundStyle(colorScheme == .light ? .black : Color.cGray)
.listRowSeparator(.hidden)
.onTapGesture {
if tree.children == nil {
changeView = true
}
}
.listRowBackground(colorScheme == .light ? .white : Color.dBackground)
}
.listRowSpacing(10)
.listStyle(.plain)
.background(colorScheme == .light ? .white : Color.dBackground)
Не следует ли listRowBackground(colorScheme == .light ? .white : Color.dBackground) менять фон каждого элемента?
Подробнее здесь:
https://stackoverflow.com/questions/784 ... in-swiftui
1715836403
Anonymous
Я не понимаю, почему listRowBackground применяется только к элементам списка без дочерних элементов и не применяется к расширяемым?
Вот как это выглядит:
список
[code]List(viewModel.tree, id: \.id, children: \.children) { tree in
HStack{
Image(systemName:tree.children != nil ? "folder" : "antenna.radiowaves.left.and.right")
.fontWeight(.medium)
Text(tree.name)
.fontWeight(.medium)
.textCase(.uppercase)
.padding(.vertical, 5)
}
.foregroundStyle(colorScheme == .light ? .black : Color.cGray)
.listRowSeparator(.hidden)
.onTapGesture {
if tree.children == nil {
changeView = true
}
}
.listRowBackground(colorScheme == .light ? .white : Color.dBackground)
}
.listRowSpacing(10)
.listStyle(.plain)
.background(colorScheme == .light ? .white : Color.dBackground)
[/code]
Не следует ли listRowBackground(colorScheme == .light ? .white : Color.dBackground) менять фон каждого элемента?
Подробнее здесь: [url]https://stackoverflow.com/questions/78448211/why-cant-i-change-the-row-background-in-a-list-in-swiftui[/url]