1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【SwiftUI】ListCellに灰色矢印を追加する

Posted at

はじめに

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("サンプルセル")
                }
            }
        }
    }
}

完成

simulator_screenshot_7AC16471-CB6A-4136-BD1B-8CB8A7FFD427.png

おわり

できました

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?