ADragDropView 1.0.3

ADragDropView 1.0.3

Axel Kee 维护。



ADragDropView

为您的 macOS 应用轻松添加拖放视图(Swift)

我在我的 Mac 应用程序中使用了这个,PDF Page Number + Watermark

Demo

要求

  • macOS 10.12+
  • Xcode 9.4.1+
  • Swift 4.1+

安装

手动安装

ADragDropView.swiftNSDraggingInfo+FilePathURL.swift 复制到 ADragDropView 文件夹下您的项目中。

CocoaPods

pod 'ADragDropView'

在视图控制器顶部添加

import ADragDropView

使用方法

在Xcode中运行ADragDropViewExample目标来尝试demo。

在Interface Builder中拖放一个自定义视图到你的视图控制器中,将其类设置为ADragDropView并为它创建一个 IBOutlet。

custom view

custom class

设置代理(通常为视图控制器),dragDropView.delegate = self .

设置允许的文件扩展名:dragDropView.acceptedFileExtensions = ["png", "jpg", "jpeg", "gif"] .

实现两个代理方法以处理拖放文件

extension ViewController: ADragDropViewDelegate {
    // when one file is dropped
    func dragDropView(_ dragDropView: ADragDropView, droppedFileWithURL URL: URL) {
        
        // action to do when the file is dropped
    }
    
    // when multiple files are dropped
    func dragDropView(_ dragDropView: ADragDropView, droppedFilesWithURLs URLs: [URL]) {
        
       // action to do when the files are dropped
    }
}