はじめに
UIKitだとcell.accessoryType = .disclosureIndicator
で灰色の矢印を付ける事ができました。
しかし、SwiftUIにはそのような機能はないのでコネコネして作ります
実装
import SwiftUI
struct NavigationButton<T: View>: View {
var action: () -> Void
@ViewBuilder var label: () -> T
var body: some View {
Button(action: action) {
NavigationLink(destination: EmptyView.init, label: label)
.foregroundColor(Color(uiColor: .label))
}
}
}
使い方
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
List {
NavigationButton {
print("押しました")
} label: {
Text("サンプルセル")
}
}
}
}
}
完成
おわり
できました