美文网首页
SwiftUI笔记

SwiftUI笔记

作者: 桃李不言的蹊 | 来源:发表于2023-08-10 17:22 被阅读0次

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()
//        }

相关文章

网友评论

      本文标题:SwiftUI笔记

      本文链接:https://www.haomeiwen.com/subject/zgjzpdtx.html