SwiftUIKit

编写起来很有趣的 UIKit 代码。

文档 (开发中)

入门

基本示例

简介

SwiftUIKit 主要基于两个函数,`embed` 和 `stack`。 将一个视图嵌入到另一个视图中正是我们在前两个例子中所做的。 现在我们可以向视图中添加另一个视图,但我们需要管理子视图的约束! 处理此问题的一个简单方法是使用 UIStackViews,因此在 SwiftUIKit 中有 VStack、HStack 和 ZStack。 UIStackViews 会为您管理约束,并且正如其名称所示,按照您给定的顺序堆叠您给定的视图。

示例代码

import UIKit
import SwiftUIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        Navigate.shared.configure(controller: navigationController)
            .set(title: "Hello SwiftUIKit")
            .setRight(barButton: BarButton {
                Button("Button 0") {
                    print("Tapped the barbutton")
                }
            })
        
        
        view.embed {
            SafeAreaView {
                List(defaultCellHeight: 60) {
                    [
                        Button("Say Hello") {
                            print("Hello World!")
                        },
                        
                        HStack(withSpacing: 8) {
                            [
                                Label("Name"),
                                
                                Divider(.vertical),
                                
                                Spacer(),
                                
                                TextField(value: "SwiftUIKit",
                                      placeholder: "Some Name",
                                      keyboardType: .default)
                                    .inputHandler { print("New Name: \($0)") }
                            ]
                        },
                        
                        Label.callout("This is some callout text!"),
                        
                        ZStack {
                            [
                                Image(.blue)
                                    .frame(height: 60, width: 60)
                                    .offset(x: 100)
                            ]
                        },
                        
                        NavButton(destination: {
                            UIViewController {
                                UIView(backgroundColor: .white) {
                                    LoadingImage(URL(string: "https://cdn11.bigcommerce.com/s-oe2q4reh/images/stencil/2048x2048/products/832/1401/Beige_Pekingese_Puppy__21677.1568609759.jpg")!)
                                        .contentMode(.scaleAspectFit)
                                }
                            }
                        }, style: .push) {
                            Label("Go see a puppy")
                        },
                        
                        Button("Show an Alert") {
                            Navigate.shared.alert(title: "Hello this is an Alert!",
                                                  message: "Just a test...",
                                                  secondsToPersist: 3)
                        },
                        
                        Button("Show an Alert w/ cancel") {
                            Navigate.shared.alert(title: "Hello World",
                                                  message: "This is an alert",
                                                  withActions: [.cancel],
                                                  secondsToPersist: 3)
                        },
                        
                        Button("Show a Toast Message") {
                            Navigate.shared.toast(style: .error, pinToTop: true, secondsToPersist: 4) {
                                Label("This is a test error message!")
                            }
                        }
                    ]
                }
            }
        }
    }
}

示例视图

Example SwiftUIKit

GitHub 支持者

suzyfendrick


oneleif 项目

这意味着该项目由 oneleif 社区赞助,合作者是来自 oneleif 的团队成员。

什么是 oneleif?

oneleif 是一个支持具有技术头脑的个人的非营利社区。 我们通过提供一个充满乐趣的社区,共同致力于开源项目来实现这一点。 我们乐于通过免费资源和指导来回馈社会。

如何加入 oneleif

点击下面的链接加入 Discord 服务器。

-或-

查看我们的网站

有问题吗?

请随时发送电子邮件至:oneleifdev@gmail.com

-或-

在 Discord 中提问