-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b00e6b
commit 9bedacd
Showing
6 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Pod::Spec.new do |s| | ||
|
||
s.name = "DropDown" | ||
s.version = "0.1" | ||
s.summary = "Android like drop down" | ||
|
||
s.description = <<-DESC | ||
This drop down is to overcome the loss of usability and user experience due to the UIPickerView. Android did a good job there so this drop down is very inspired by it. It appears at the right location instead of the bottom of the screen as default with UIPickerView and if possible, all options are displayed at once. | ||
DESC | ||
|
||
s.homepage = "https://github.com/kevin-hirsch/DropDown" | ||
s.screenshots = "https://github.com/kevin-hirsch/DropDown/tree/master/Screenshots/1.png", "https://github.com/kevin-hirsch/DropDown/tree/master/Screenshots/2.png" | ||
|
||
s.license = { :type => "MIT", :file => "LICENSE" } | ||
|
||
s.author = { "kevin-hirsch" => "[email protected]" } | ||
s.social_media_url = "http://twitter.com/kevinh6113" | ||
|
||
s.platform = :ios, '7.0' | ||
s.source = { | ||
:git => "https://github.com/kevin-hirsch/DropDown.git", | ||
:tag => s.version.to_s | ||
} | ||
|
||
s.source_files = "DropDown/src", "DropDown/src/**/*.{h,m}", "DropDown/helpers", "DropDown/helpers/**/*.{h,m}" | ||
s.resources = "DropDown/resources/*.{png,xib}" | ||
s.requires_arc = true | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 kevin-hirsch | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
 | ||
|
||
[](https://twitter.com/kevinh6113) | ||
[](https://github.com/kevin-hirsch/KVNProgress/blob/master/README.md) | ||
[](https://github.com/kevin-hirsch/DropDown) | ||
[](http://cocoadocs.org/docsets/DropDown/) | ||
|
||
A drop down for iOS in Swift (1.2). | ||
*** | ||
|
||
[](Screenshots/1.png) | ||
[](Screenshots/2.png) | ||
|
||
## Installation | ||
|
||
### Cocoapods | ||
|
||
Use [CocoaPods](http://www.cocoapods.org). | ||
|
||
1. Add `pod 'DropDown'` to your *Podfile*. | ||
2. Install the pod(s) by running `pod install`. | ||
|
||
### Source files | ||
|
||
1. Download the [latest code version](http://github.com/kevin-hirsch/DropDown/archive/master.zip) or add the repository as a git submodule to your git-tracked project. | ||
2. Drag and drop the **src**, **helpers** and also the **resources** directory from the archive in your project navigator. Make sure to select *Copy items* when asked if you extracted the code archive outside of your project. | ||
|
||
## Usage | ||
|
||
Create a new drop down: | ||
|
||
```swift | ||
let dropDown = DropDown() | ||
``` | ||
|
||
Set the view to which the drop down will anchor: | ||
|
||
```swift | ||
let view = UIView() | ||
dropDown.anchorView = view | ||
``` | ||
|
||
By default, the dropdown will be shown from the point (0, 0). If you want the dropdown to be just below your anchor view, you can precise an offset like this: | ||
|
||
```swift | ||
dropDown.offset = CGPoint(x: 0, y:view.bounds.height) | ||
``` | ||
|
||
The default width of the drop down will be the same as the anchor view minus the offset. If you want a custom width, just set: | ||
|
||
```swift | ||
dropDown.width = 100 | ||
``` | ||
|
||
Set the data source: | ||
|
||
```swift | ||
dropDown.dataSource = ["Car", "Motorcycle", "Van"] | ||
``` | ||
|
||
When the user select something, your `selectionAction` is called: | ||
|
||
```swift | ||
dropDown.selectionAction = { [unowned self] (index, string) in | ||
println("item \(string) at index \(index) selected.") | ||
} | ||
``` | ||
|
||
And if the user cancels the drop down, your `cancelAction` gets called: | ||
|
||
```swift | ||
dropDown.cancelAction = { [unowned self] in | ||
println("Drop down canceled") | ||
} | ||
``` | ||
|
||
You have 3 dismiss mode with the `DismissMode` enum: | ||
|
||
- `OnTap`: a tap is needed to dismiss the drop down before being able to interact with the UI | ||
- `Automatic`: no tap is needed to dismiss the drop down, as soon as the user interact with anything else than the drop down, the drop down is dismissed | ||
- `Manual`: the drop down can only be dismissed manually (by code) | ||
|
||
for example: | ||
|
||
```swift | ||
dropDown.dismissMode = .Automatic | ||
``` | ||
|
||
You can (pre)select a row with: | ||
|
||
```swift | ||
dropDown.selectRowAtIndex(3) | ||
``` | ||
|
||
And finally show and hide the drop down with: | ||
|
||
```swift | ||
dropDown.show() | ||
dropDown.hide() | ||
``` | ||
|
||
The data source is reloaded automatically when changing the `dataSource` property. If needed, you can reload the data source manually by doing: | ||
|
||
```swift | ||
dropDown.reloadAllComponents() | ||
``` | ||
|
||
You can get info about the selected item this way: | ||
|
||
```swift | ||
dropDown.selectedItem() // returns a String? | ||
dropDown.indexForSelectedRow() // returns a Index? | ||
``` | ||
|
||
### Advanced usage | ||
|
||
when calling the `show` method, it returns a tuple like this: | ||
|
||
```swift | ||
(canBeDisplayed: Bool, offscreenHeight: CGFloat?) | ||
``` | ||
|
||
- `canBeDisplayed` tells if there is enough height to display the drop down. If its value is `false`, the drop down is not showed. | ||
- `offscreenHeight`: if the drop down was not able to show all options from the data source at once, `offscreenHeight` will contain the height needed to display all options at once (without having to scroll through them). This can be used in a scroll view or table view to scroll enough before showing the drop down. | ||
|
||
## Remains to do | ||
|
||
- [ ] Handle landscape mode on iOS 7 | ||
|
||
## Requirements | ||
|
||
* Xcode 6+ | ||
* iOS 7+ | ||
* ARC | ||
|
||
## License | ||
|
||
This project is under MIT license. For more information, see `LICENSE` file. | ||
|
||
## Credits | ||
|
||
DropDown was inspired by the Material Design version of the [Spinner](http://developer.android.com/guide/topics/ui/controls/spinner.html). | ||
|
||
DropDown was done to integrate in a project I work on: | ||
[](https://assis.to). | ||
It will be updated when necessary and fixes will be done as soon as discovered to keep it up to date. | ||
|
||
I work at | ||
[(http://pinchproject.com). | ||
|
||
You can find me on Twitter [@kevinh6113](https://twitter.com/kevinh6113). | ||
|
||
Enjoy! :) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.