Swiftpack.co - aruis/FlipView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by aruis.
aruis/FlipView 1.22.12
基于SwiftUI 实现一个简单的翻页时钟(Flip)效果
⭐️ 1
🕓 1 week ago
iOS macOS
.package(url: "https://github.com/aruis/FlipView.git", from: "1.22.12")

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

GitHub

link
Stars: 1
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics