zoukankan      html  css  js  c++  java
  • 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()
        }
    }
    
  • 相关阅读:
    python-历史
    10-函数命名空间,作用域,嵌套,闭包
    centos7 搭建dns服务器
    centos7 搭建dhcp服务器
    Nginx 启用 gzip 压缩
    Eclipse 个人手册
    Nginx 命令
    定时任务
    系统设计
    根据 xsd 生成 jaxb java 类
  • 原文地址:https://www.cnblogs.com/chaostudy/p/15034798.html
Copyright © 2011-2022 走看看