SwiftUI List with Section Index on right hand side?

前端 未结 4 1071
旧时难觅i
旧时难觅i 2021-02-03 13:23

Is it possible to have a List with an index on the right hand side, like the example below in SwiftUI?

\"Example\"<

4条回答
  •  你的背包
    2021-02-03 13:54

    I've made a couple of changes to @Mozahler's and @DirectX's code, refining the result.

    1. I didn't want the main list to include headers with no content, so in the implementation the line under List { becomes:

      ForEach(indexes, id: \.self) { letter in
      

      rather than

      ForEach(alphabet, id: \.self) { letter in
      
    2. Setting a background and uniform width for the index column sets it off from any background and unifies the result:

      Text(letter)
          .frame(width: 16)
          .foregroundColor(Constants.color.textColor)
          .background(Color.secondary.opacity(0.5))
          .font(Constants.font.customFootnoteFont)
          .padding(.trailing, 7)
      

提交回复
热议问题