Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cupnoodle/ADragDropView
Add a Drag and drop view (swift) for your macOS app easily
https://github.com/cupnoodle/ADragDropView
drag-and-drop drag-drop macos
Last synced: about 2 months ago
JSON representation
Add a Drag and drop view (swift) for your macOS app easily
- Host: GitHub
- URL: https://github.com/cupnoodle/ADragDropView
- Owner: cupnoodle
- License: mit
- Created: 2018-09-24T15:34:15.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-11T18:14:51.000Z (over 5 years ago)
- Last Synced: 2024-08-05T12:17:33.624Z (about 2 months ago)
- Topics: drag-and-drop, drag-drop, macos
- Language: Swift
- Size: 310 KB
- Stars: 45
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ADragDropView
[![Build Status](https://travis-ci.org/cupnoodle/ADragDropView.svg?branch=master)](https://travis-ci.org/cupnoodle/ADragDropView)
> Add a Drag and drop view (swift) for your macOS app easily
I used this in my mac apps, [Pushever, test APNS push notification easily](https://itunes.apple.com/us/app/pushever-apns-tester/id1455738387?ls=1&mt=12) and [PDF Page Numberer](https://pdfpagenumber.com).
![Demo](demo.gif)
## Requirements
- macOS 10.12+
- Xcode 9.4.1+
- Swift 4.1+## Install
### Manual
Copy the `ADragDropView.swift` and `NSDraggingInfo+FilePathURL.swift` inside the `ADragDropView` folder to your project.### CocoaPods
```ruby
pod 'ADragDropView'
```On the top of view controller, add
```swift
import ADragDropView
```## Usage
*Run the `ADragDropViewExample` target in Xcode to try the demo.*
Drag and drop a **Custom View** to your view controller in Interface Builder, set its class to **ADragDropView** and create an IBOutlet for it.
![custom view](customView.png)
![custom class](customClass.png)
Set delegate (usually to the view controller), `dragDropView.delegate = self` .
Set the allowed file extensions: `dragDropView.acceptedFileExtensions = ["png", "jpg", "jpeg", "gif"]` .
Implement the two delegate methods to handle dropped file(s) :
```swift
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
}
}
```