• SwiftUI 中Stepper的使用


    效果如下

    import SwiftUI
    
    struct ContentView: View {
        @State private var selectIndex = 0
        let color: [Color] = [.orange,.red,.gray,.blue,.green,.purple,.pink]
        
        @State private var value = 0
        @State private var circleSize :CGFloat = 20
        let step = 5
        let range = 0...50
        var body: some View {
           
            
            VStack {
                Stepper(value: $value, in: range, step: step) { (isEditable) in
                    print("soso (isEditable)")
                } label: {
                    Text("当前值为:(value)")
                }
                
                Stepper(onIncrement: increment, onDecrement: decrement) {
                    Text("array index = (selectIndex) color:(color[selectIndex].description)")
                }.background(color[selectIndex])
                
                Stepper("",value: $circleSize,in: 10...500,step: 10)
                    .labelsHidden()
                Circle()
                    .frame( circleSize, height: circleSize)
                    .foregroundColor(Color.blue)
                    .animation(.easeInOut)
            }
    
            
        }
        private func increment(){
            selectIndex += 1
            if selectIndex >= color.count{selectIndex = 0}
        }
        private func decrement(){
            selectIndex -= 1
            if selectIndex <= 0{selectIndex = color.count-1}
        }
    }
    
    
    
    struct ContentView_Previews: PreviewProvider {
        static var previews: some View {
            ContentView()
        }
    }
    
  • 相关阅读:
    移动端 推送的那些东西
    git 常用命令
    顶部提示 先下移出来 再上移出去
    ViewPager 高度自适应
    进制转换
    Android 适配
    适配三星Galaxy S8及S8+ 屏幕比例为 18.5:9
    dpi dp px 换算关系
    资源前缀及代码分析总结
    判断是否快速点击或者滑动
  • 原文地址:https://www.cnblogs.com/chaostudy/p/15034798.html
Copyright © 2020-2023  润新知