Git Product home page Git Product logo

flipview's Introduction

FlipView

用SwiftUI实现的,一个简单的翻页时钟效果。

使用

File > Swift Packages > Add Package Dependency: https://github.com/aruis/FlipView.git

CleanShot-2022-05-31-11 02 57

import SwiftUI

struct FlipClockDemo: View {
    
    public var body: some View {
        
        GeometryReader{ geometry in
            let size = geometry.size
            let width = size.width / 8
            let height = width*2
            
                TimelineView(.periodic(from: .now, by: 1)) { context in
                    let arr = Array( context.date.format("HHmmss")).map{String($0)}
                    
                    ZStack{
                        HStack{
                            ForEach(0...5, id: \.self) {i in
                                FlipView(.constant( arr[i]), flipColor: .constant(.black), gap: 3)
                                    .frame(width: width, height: height)
                                    .foregroundColor(.white)
                                    .clipShape(RoundedRectangle(cornerRadius: 5, style: .continuous))
                            }                            
                        }
                        
                    }
                    .padding(40)
                    
                }
                .position(x: size.width/2, y: size.height/2)
                
            
        }
    }
}

也可以把其中一个Flip单独拿出来,做自己想要的文字展示效果

CleanShot-2022-05-31-11 05 19

import SwiftUI

struct FlipViewDemo: View {
    
    @State var i = 0
    
    
    var body: some View {
        VStack{
            FlipView( .constant(String(i)) ,flipColor: .constant(.brown))
                .frame(width: 100, height: 200)
                .foregroundColor(.white)
                .cornerRadius(10)
            
            Text("\(i)")
            Button("test"){
                i += 1
                
            }
        }
        .background(.background)
    }
}

struct FlipViewDemo_Previews: PreviewProvider {
    static var previews: some View {
        FlipViewDemo()
    }
}

flipview's People

Contributors

aruis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.