Код: Выделить всё
public struct DropDownRow: View {
private let titleContent: TitleContent
private let subtitleContent: SubtitleContent
private let menuOptions: [String]?
@Binding private var selectedIndex: Int
private var onSelection: ((Int, String) -> Void)?
private var item: String?
public var body: some View {
HStack {
VStack(alignment: .leading, spacing: 4) {
titleContent
.font(.title)
.foregroundColor(.white)
.fontWeight(.regular)
subtitleContent
.font(.caption)
.foregroundColor(.gray)
.fontWeight(.regular)
}
Spacer()
Menu {
if let options = menuOptions {
ForEach(options.indices, id:\.self) { index in
Button {
self.selectedIndex = index
if let type = item {
self.onSelection?(index, type)
}
} label: {
HStack{
if index == selectedIndex {
Image(systemName: "checkmark")
}
Text(options[index])
Spacer()
}
}
}
}
} label: {
HStack {
Image(systemName: "chevron.down")
.resizable()
.renderingMode(.template)
.aspectRatio(contentMode: .fit)
.foregroundColor(.gray)
.frame(width: 16, height: 16, alignment: .trailing)
}
.padding(.leading, 16)
.padding([.trailing, .vertical], 6)
}
}
.padding(16)
.cornerRadius(10)
.accessibilityAddTraits(.isButton)
.noListSeparators()
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... of-the-sel
Мобильная версия