You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

不使用List时,如何在LazyVStack行中添加系统披露指示器?

实现LazyVStack自定义行添加系统原生披露指示器

方法一:基于UIKit包装(合规无风险)

通过UIViewRepresentable包装UIKit原生的UITableViewCell披露指示器,完全复用系统样式,不会触发审核问题:

struct SystemDisclosureIndicator: UIViewRepresentable {
    func makeUIView(context: Context) -> UIView {
        let indicatorCell = UITableViewCell()
        indicatorCell.accessoryType = .disclosureIndicator
        indicatorCell.backgroundColor = .clear
        indicatorCell.selectionStyle = .none
        return indicatorCell
    }
    
    func updateUIView(_ uiView: UIView, context: Context) {}
}

使用示例

将自定义行与指示器结合,通过NavigationLink实现跳转逻辑,同时保留你的定制化UI:

LazyVStack(spacing: 12) {
    ForEach(0..<5) { index in
        NavigationLink {
            // 跳转目标视图
            Text("详情页面 \(index)")
        } label: {
            HStack {
                Text("自定义行内容 \(index)")
                    .padding(.vertical, 16)
                    .padding(.horizontal)
                Spacer()
                SystemDisclosureIndicator()
                    .padding(.trailing, 16)
            }
            .background(Color(UIColor.systemGray5))
            .cornerRadius(12)
            .padding(.horizontal, 16)
        }
        .buttonStyle(.plain) // 移除NavigationLink默认的高亮样式
    }
}

方法二:SwiftUI私有视图(简洁但有审核风险)

如果愿意承担私有API的审核风险,可以直接调用SwiftUI内部的_DisclosureIndicator视图,这是系统List中NavigationLink指示器的原生实现:

struct SystemDisclosureIndicator: View {
    var body: some View {
        _DisclosureIndicator()
            .foregroundColor(Color(UIColor.systemGray))
    }
}

使用方式与方法一完全一致,无需额外修改。

内容的提问来源于stack exchange,提问作者lazarevzubov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 08:26:24