SwiftUI笔记

1.ForEach警告,逻辑不执行的: Non-constant range: argument must be an integer literal


7411691745477_.pic.jpg

改为

ForEach(0 ..< count, id:\.self) {
}
7421691745678_.pic.jpg

2.处理onTapGesture 点击空白区域无效的 自定义扩展onTapExpandArea,使用自定义的

private struct LBExpandAreaTap: ViewModifier {
    func body(content: Content) -> some View {
        ZStack {
            Rectangle()
                .foregroundColor(Color.white)
                .contentShape(Rectangle())
            content
        }
    }
}

extension View {
    public func onTapExpandArea(tap: @escaping () -> ()) -> some View {
        self.modifier(LBExpandAreaTap()).onTapGesture(perform: tap)
    }
}

3.List间距的,去掉list内间距的.listStyle(.plain),去掉listItem间距的.listRowInsets(EdgeInsets())

List{
            Section(header: Text("蓝牙设备").bold().foregroundColor(.black).font(.title).padding(.bottom,10)) {
                listItemViews.listRowInsets(EdgeInsets())///去掉listItem的间距  靠边的
            }
        }.task {
            self.bluetoothManager.initBluetoothManager()
        }.onDisappear{
            self.bluetoothManager.stopScanPeripherals()
        }
        ///去掉内间距
//        .listStyle(.plain)
        ///外间距
//        .padding(.all,20)
//        .onAppear{
//            self.bluetoothManager.initBluetoothManager()
//        }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容