GreatActions 0.1.1

GreatActions 0.1.1

Tienvv88 维护。



  • 作者
  • tienvv88

GreatActions

Group 13540

需求

Swift 5.x, iOS 17+

示例

hold_process_demo.mov

要运行示例项目,请克隆存储库,然后首先从 Example 文件夹中运行 pod install

安装

Cocoapods

HoldProcessAction 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中:

pod 'GreatActions'

Swift 包管理器

  1. 文件 > Swift 包 > 添加包依赖
  2. 添加 https://github.com/tienvv88/GreatActions.git

或者

更新 Package.swift 中的 dependencies

dependencies: [.package(url: "[https://github.com/tienvv88/GreatActions.git]", .upToNextMajor(from: "0.1.0"))]

演示

用法

SwiftUI

  import SwiftUI
  import GreatActions

  struct SwiftUISample: View {

  @State private var status: String = "--"

  var body: some View {
      VStack {
          Text(status)
          HoldActions(title: "Test Hold Down Action",
                      duration: 2.0,
                      background: .black,
                      loadingTint: .white.opacity(0.5),
                      onChanged: {
              self.status = "Holding🚀"
          }, onCancel: {
              self.status = "Cancel🥲"
          }, onEnded: {
              self.status = "Done💖"
          })
      }
  }
}

#Preview {
  SwiftUISample()
}

UIKit

 import UIKit
import SwiftUI
import GreatActions

class ViewController: UIViewController {

  private var statusLabel: UILabel!

  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.

      let holdDownAction = HoldActions(title: "Test Hold Down Action",
                                       duration: 2.0,
                                       background: .black,
                                       loadingTint: .white.opacity(0.5),
                                       onChanged: {
          self.statusLabel.text = "Holding🚀"
      }, onCancel: {
          self.statusLabel.text = "Cancel🥲"
      }, onEnded: {
          self.statusLabel.text = "Done💖"
      })

      let hostingView = UIHostingController(rootView: holdDownAction)

      let swiftUIView = hostingView.view ?? UIView()
      swiftUIView.translatesAutoresizingMaskIntoConstraints = false

      addChild(hostingView)
      view.addSubview(swiftUIView)

      // Create and activate the constraints for the swiftui's view.
      NSLayoutConstraint.activate([
          swiftUIView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
          swiftUIView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
          swiftUIView.widthAnchor.constraint(equalToConstant: view.frame.width),
          swiftUIView.heightAnchor.constraint(equalToConstant: 100)
      ])

      hostingView.didMove(toParent: self)

      // setup status label
      statusLabel = UILabel()
      statusLabel.text = "--"
      statusLabel.textAlignment = .center
      statusLabel.translatesAutoresizingMaskIntoConstraints = false
      view.addSubview(statusLabel)

      NSLayoutConstraint.activate([
          statusLabel.centerXAnchor.constraint(equalTo: swiftUIView.centerXAnchor),
          statusLabel.bottomAnchor.constraint(equalTo: swiftUIView.topAnchor, constant: 10),
          statusLabel.widthAnchor.constraint(equalToConstant: 100),
          statusLabel.heightAnchor.constraint(equalToConstant: 20)
      ])
  }

  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }

}

作者

tienvv88, [email protected]

许可证

GreatActions 可在 MIT 许可证下获得。有关更多信息,请参阅 LICENSE 文件。