├── .swift-version
├── DKDropMenu.gif
├── DKDropMenu.png
├── DKDropMenu.xcodeproj
├── project.xcworkspace
│ └── contents.xcworkspacedata
└── project.pbxproj
├── CHANGELOG.md
├── DKDropMenu.podspec
├── .gitignore
├── DKDropMenu
├── ViewController.swift
├── Images.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Info.plist
├── AppDelegate.swift
└── Base.lproj
│ ├── Main.storyboard
│ └── LaunchScreen.xib
├── LICENSE
├── README.md
└── DKDropMenu.swift
/.swift-version:
--------------------------------------------------------------------------------
1 | 4.0
2 |
--------------------------------------------------------------------------------
/DKDropMenu.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davecom/DKDropMenu/HEAD/DKDropMenu.gif
--------------------------------------------------------------------------------
/DKDropMenu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davecom/DKDropMenu/HEAD/DKDropMenu.png
--------------------------------------------------------------------------------
/DKDropMenu.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ### 0.3.0
2 | - Swift 4 Support
3 | - Removed Test Target from Sample Project
4 |
5 | ### 0.2.0
6 | - Swift 3 Support
7 | - Added removeAll() method
8 | - Renamed methods
9 | - Renamed delegate methods
10 |
11 | ### 0.1.6
12 | - Fixed alignment issue
13 |
14 | ### 0.1.5
15 | - Swift 2 Support
16 |
17 | ### 0.1.4
18 | - Font options
19 |
20 | ### 0.1.3
21 | - Added collapsedChanged() delegate method
22 |
23 | ### 0.1.2
24 | - Line cleanup
25 |
26 | ### 0.1.1
27 | - Added font options
28 |
29 | ### 0.1.0
30 | - Initial release
31 |
--------------------------------------------------------------------------------
/DKDropMenu.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = 'DKDropMenu'
3 | s.version = '0.3.0'
4 | s.license = 'MIT'
5 | s.summary = 'A simple iOS drop down list written in Swift.'
6 | s.homepage = 'https://github.com/davecom/DKDropMenu'
7 | s.social_media_url = 'https://twitter.com/davekopec'
8 | s.authors = { 'David Kopec' => 'david@oaksnow.com' }
9 | s.source = { :git => 'https://github.com/davecom/DKDropMenu.git', :tag => s.version }
10 | s.screenshot = 'https://raw.githubusercontent.com/davecom/DKDropMenu/master/DKDropMenu.png'
11 |
12 | s.ios.deployment_target = '8.0'
13 |
14 | s.framework = 'UIKit'
15 | s.source_files = 'DKDropMenu.swift'
16 | s.requires_arc = true
17 | end
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | # Xcode
3 | #
4 | build/
5 | *.pbxuser
6 | !default.pbxuser
7 | *.mode1v3
8 | !default.mode1v3
9 | *.mode2v3
10 | !default.mode2v3
11 | *.perspectivev3
12 | !default.perspectivev3
13 | xcuserdata
14 | *.xccheckout
15 | *.moved-aside
16 | DerivedData
17 | *.hmap
18 | *.ipa
19 | *.xcuserstate
20 |
21 | # CocoaPods
22 | #
23 | # We recommend against adding the Pods directory to your .gitignore. However
24 | # you should judge for yourself, the pros and cons are mentioned at:
25 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
26 | #
27 | # Pods/
28 |
29 | # Carthage
30 | #
31 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
32 | # Carthage/Checkouts
33 |
34 | Carthage/Build
35 |
--------------------------------------------------------------------------------
/DKDropMenu/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // DKDropMenu
4 | //
5 | // Created by David Kopec on 6/5/15.
6 | // Copyright (c) 2015 Oak Snow Consulting. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | class ViewController: UIViewController, DKDropMenuDelegate {
12 | @IBOutlet weak var dropMenu: DKDropMenu!
13 |
14 | override func viewDidLoad() {
15 | super.viewDidLoad()
16 | // Do any additional setup after loading the view, typically from a nib.
17 |
18 | dropMenu.add(names: ["hello", "goodbye", "why?"])
19 | dropMenu.delegate = self
20 | }
21 |
22 | override func didReceiveMemoryWarning() {
23 | super.didReceiveMemoryWarning()
24 | // Dispose of any resources that can be recreated.
25 | }
26 |
27 | // MARK: DKDropMenuDelegate
28 | func itemSelected(withIndex: Int, name: String) {
29 | print("\(name) selected");
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The DKDropMenu License
2 |
3 | Copyright (c) 2015 David Kopec
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/DKDropMenu/Images.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/DKDropMenu/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DKDropMenu
2 | DKDropMenu is a simple iOS drop down list written in Swift. It expands and collapses. It allows the user to select only one item at a time. Items are just Strings. A delegate is notified when selection occurs. DKDropMenu is IBDesignable and IBInspectable with customizable colors, font, and row heights.
3 |
4 | 
5 | 
6 |
7 | ## Installation
8 | Use the cocoapod `DKDropMenu` or simply include `DKDropMenu.swift` in your project. DKDropMenu 0.3.0 and above requires Swift 4. Use version 0.2.0 for Swift 3 Support. Use version 0.1.6 for Swift 2 support.
9 |
10 | ## Usage
11 | Create a DKDropMenu in IB or in code (using UIView's init methods). Then add items and set a delegate:
12 | ```
13 | dropMenu.add(names: ["hello", "goodbye", "why?"])
14 | dropMenu.delegate = self
15 | ```
16 | Make sure to implement the single method the delegate (DKDropMenuDelegate) must implement:
17 | ```
18 | func itemSelected(withIndex: Int, name: String) {
19 | println("\(name) selected");
20 | }
21 | ```
22 | The delegate can also optionally implement the method
23 | ```
24 | func collapsedChanged()
25 | ```
26 | to be notified when the collapse status of the menu changes.
27 |
28 | Items can be added or removed
29 | ```
30 | func add(names: [String])
31 | func add(name: String)
32 | func remove(atIndex: Int)
33 | func remove(name: String)
34 | func removeAll()
35 | ```
36 | The properties `collapsed` (Bool) and `selectedItem` (String) can be manually modified.
37 |
38 | ## License and Authorship
39 | Released under the MIT License. Copyright 2015-2016 David Kopec. Please open issues on GitHub.
40 |
--------------------------------------------------------------------------------
/DKDropMenu/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // DKDropMenu
4 | //
5 | // Created by David Kopec on 6/5/15.
6 | // Copyright (c) 2015 Oak Snow Consulting. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 |
17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
18 | // Override point for customization after application launch.
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(_ application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(_ application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(_ application: UIApplication) {
33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(_ application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(_ application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 |
44 |
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/DKDropMenu/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/DKDropMenu/Base.lproj/LaunchScreen.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/DKDropMenu.swift:
--------------------------------------------------------------------------------
1 | //The DKDropMenu License
2 | //
3 | //Copyright (c) 2015-2016 David Kopec
4 | //
5 | //Permission is hereby granted, free of charge, to any person obtaining a copy
6 | //of this software and associated documentation files (the "Software"), to deal
7 | //in the Software without restriction, including without limitation the rights
8 | //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | //copies of the Software, and to permit persons to whom the Software is
10 | //furnished to do so, subject to the following conditions:
11 | //
12 | //The above copyright notice and this permission notice shall be included in all
13 | //copies or substantial portions of the Software.
14 | //
15 | //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | //FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | //AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | //LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | //OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | //SOFTWARE.
22 |
23 | //
24 | // DKDropMenu.swift
25 | // DKDropMenu
26 | //
27 | // Created by David Kopec on 6/5/15.
28 | // Copyright (c) 2015 Oak Snow Consulting. All rights reserved.
29 | //
30 |
31 | import UIKit
32 |
33 | /// Delegate protocol for receiving change in list selection
34 | @objc public protocol DKDropMenuDelegate {
35 | func itemSelected(withIndex: Int, name:String)
36 | @objc optional func collapsedChanged()
37 | }
38 |
39 | /// A simple drop down list like expandable menu for iOS
40 | @IBDesignable
41 | public class DKDropMenu: UIView {
42 |
43 | @IBInspectable public var itemHeight: CGFloat = 44
44 | @IBInspectable public var selectedFontName: String = "HelveticaNeue-Bold"
45 | @IBInspectable public var listFontName: String = "HelveticaNeue-Thin"
46 | @IBInspectable public var textColor: UIColor = UIColor.darkGray
47 | @IBInspectable public var outlineColor: UIColor = UIColor.lightGray
48 | @IBInspectable public var selectedColor: UIColor = UIColor.green
49 | weak public var delegate: DKDropMenuDelegate? = nil //notified when a selection occurs
50 | private var items: [String] = [String]()
51 | public var selectedItem: String? = nil {
52 | didSet {
53 | setNeedsDisplay()
54 | }
55 | }
56 | public var collapsed: Bool = true {
57 | didSet {
58 | delegate?.collapsedChanged?()
59 | //animate collapsing or opening
60 | UIView.animate(withDuration: 0.5, delay: 0, options: .transitionCrossDissolve, animations: {
61 | var tempFrame = self.frame
62 | if (self.collapsed) {
63 | tempFrame.size.height = self.itemHeight
64 | } else {
65 | if (self.items.count > 1 && self.selectedItem != nil) {
66 | tempFrame.size.height = self.itemHeight * CGFloat(self.items.count)
67 | } else if (self.items.count > 0 && self.selectedItem == nil) {
68 | tempFrame.size.height = self.itemHeight * CGFloat(self.items.count) + self.itemHeight
69 | }
70 | }
71 | self.frame = tempFrame
72 | self.invalidateIntrinsicContentSize()
73 | }, completion: nil)
74 | setNeedsDisplay()
75 | }
76 | }
77 |
78 | // MARK: Overridden standard UIView methods
79 | override public func sizeThatFits(_ size: CGSize) -> CGSize {
80 | if (items.count < 2 || collapsed) {
81 | return CGSize(width: size.width, height: itemHeight)
82 | } else {
83 | return CGSize(width: size.width, height: (itemHeight * CGFloat(items.count)))
84 | }
85 | }
86 |
87 | override public var intrinsicContentSize: CGSize {
88 | if (items.count < 2 || collapsed) {
89 | return CGSize(width: bounds.size.width, height: itemHeight)
90 | } else {
91 | return CGSize(width: bounds.size.width, height: (itemHeight * CGFloat(items.count)))
92 | }
93 | }
94 |
95 | override public func draw(_ rect: CGRect) {
96 | // Drawing code
97 | //draw first box regardless
98 | let context = UIGraphicsGetCurrentContext()
99 | outlineColor.setStroke()
100 | context?.setLineWidth(1.0)
101 | context?.move(to: CGPoint(x: 0, y: itemHeight))
102 | context?.addLine(to: CGPoint(x: 0, y: 0.5))
103 | context?.addLine(to: CGPoint(x: frame.size.width, y: 0.5))
104 | context?.addLine(to: CGPoint(x: frame.size.width, y: itemHeight))
105 | context?.strokePath()
106 | if let sele = selectedItem {
107 | //draw item text
108 | let paragraphStyle = NSMutableParagraphStyle()
109 | paragraphStyle.alignment = .center
110 | let attrs = [NSAttributedStringKey.font: UIFont(name: selectedFontName, size: 16)!, NSAttributedStringKey.paragraphStyle: paragraphStyle, NSAttributedStringKey.foregroundColor: textColor]
111 | if (collapsed) {
112 | let tempS = "\(sele)" //put chevron down facing here if right unicode found
113 | tempS.draw(in: CGRect(x: 20, y: itemHeight / 2 - 10, width: frame.size.width - 40, height: 20), withAttributes: attrs)
114 | } else {
115 | let tempS = "\(sele)" //put chevron up facing here if right unicode found
116 | tempS.draw(in: CGRect(x: 20, y: itemHeight / 2 - 10, width: frame.size.width - 40, height: 20), withAttributes: attrs)
117 | }
118 | //draw selected line
119 | selectedColor.setStroke()
120 | context?.move(to: CGPoint(x: 0, y: itemHeight - 2))
121 | context?.setLineWidth(4.0)
122 | context?.addLine(to: CGPoint(x: frame.width, y: itemHeight - 2))
123 | context?.strokePath()
124 | } else {
125 | context?.move(to: CGPoint(x: 0, y: itemHeight - 1))
126 | context?.setLineWidth(1.0)
127 | context?.addLine(to: CGPoint(x: frame.width, y: itemHeight - 1))
128 | context?.strokePath()
129 | }
130 | //draw lower boxes
131 | if (!collapsed && items.count > 1) {
132 | var currentY = itemHeight
133 | for item in items {
134 | if item == selectedItem {
135 | continue
136 | }
137 | //draw box
138 | outlineColor.setStroke()
139 | context?.setLineWidth(1.0)
140 | context?.move(to: CGPoint(x: 0, y: currentY))
141 | context?.addLine(to: CGPoint(x: 0, y: currentY + itemHeight))
142 | context?.strokePath()
143 | context?.setLineWidth(0.5)
144 | context?.move(to: CGPoint(x: 0, y: currentY + itemHeight - 1))
145 | context?.addLine(to: CGPoint(x: frame.size.width, y: currentY + itemHeight - 1))
146 | context?.strokePath()
147 | context?.setLineWidth(1.0)
148 | context?.move(to: CGPoint(x: frame.size.width, y: currentY + itemHeight))
149 | context?.addLine(to: CGPoint(x: frame.size.width, y: currentY))
150 | context?.strokePath()
151 | //draw item text
152 | let paragraphStyle = NSMutableParagraphStyle()
153 | paragraphStyle.alignment = .center
154 | let attrs = [NSAttributedStringKey.font: UIFont(name: listFontName, size: 16)!, NSAttributedStringKey.paragraphStyle: paragraphStyle, NSAttributedStringKey.foregroundColor: textColor]
155 | item.draw(in: CGRect(x: 20, y: currentY + (itemHeight / 2 - 10), width: frame.size.width - 40, height: 20), withAttributes: attrs)
156 | currentY += itemHeight
157 | }
158 | }
159 | }
160 |
161 | // MARK: Add or remove items
162 | /// Add an array of items to the menu
163 | public func add(names: [String]) {
164 | for name in names {
165 | add(name: name)
166 | }
167 | }
168 |
169 | /// Add a single item to the menu
170 | public func add(name: String) {
171 | //if we have no selected items, we'll take it
172 | if items.isEmpty {
173 | selectedItem = name
174 | }
175 |
176 | items.append(name)
177 |
178 | //animate change
179 | if (!collapsed && items.count > 1) {
180 | UIView.animate(withDuration: 0.7, delay: 0, options: .curveEaseOut, animations: {
181 | var tempFrame = self.frame
182 | tempFrame.size.height = self.itemHeight * CGFloat(self.items.count)
183 | self.frame = tempFrame
184 | }, completion: nil)
185 | }
186 |
187 | //refresh display
188 | setNeedsDisplay()
189 | }
190 |
191 | /// Remove a single item from the menu
192 | public func remove(at index: Int) {
193 | if (items[index] == selectedItem) {
194 | selectedItem = nil
195 | }
196 | items.remove(at: index)
197 | //animate change
198 | if (!collapsed && items.count > 1) {
199 | UIView.animate(withDuration: 0.7, delay: 0, options: .curveEaseOut, animations: {
200 | var tempFrame = self.frame
201 | tempFrame.size.height = self.itemHeight * CGFloat(self.items.count)
202 | self.frame = tempFrame
203 | }, completion: nil)
204 | } else if (!collapsed) {
205 | UIView.animate(withDuration: 0.7, delay: 0, options: .curveEaseOut, animations: {
206 | var tempFrame = self.frame
207 | tempFrame.size.height = self.itemHeight
208 | self.frame = tempFrame
209 | }, completion: nil)
210 | }
211 |
212 | setNeedsDisplay()
213 | }
214 |
215 | /// Remove the first occurence of item named *name*
216 | public func remove(name: String) {
217 | if let index = items.index(of: name) {
218 | remove(at: index)
219 | }
220 | }
221 |
222 | /// Remove all items
223 | public func removeAll() {
224 | selectedItem = nil
225 | items.removeAll()
226 | if (!collapsed) {
227 | UIView.animate(withDuration: 0.7, delay: 0, options: .curveEaseOut, animations: {
228 | var tempFrame = self.frame
229 | tempFrame.size.height = self.itemHeight
230 | self.frame = tempFrame
231 | }, completion: nil)
232 | }
233 |
234 | setNeedsDisplay()
235 | }
236 |
237 | // MARK: Events
238 | override public func touchesEnded(_ touches: Set, with event: UIEvent?) {
239 | let touch: UITouch = touches.first!
240 | let point: CGPoint = touch.location(in: self)
241 | if point.y > itemHeight {
242 | if let dele = delegate {
243 | var thought = Int(point.y / itemHeight) - 1
244 | if let sele = selectedItem {
245 | if items.index(of: sele)! <= thought {
246 | thought += 1
247 | }
248 | }
249 | dele.itemSelected(withIndex: thought, name: items[thought])
250 | selectedItem = items[thought]
251 | }
252 | }
253 | collapsed = !collapsed
254 | }
255 | }
256 |
--------------------------------------------------------------------------------
/DKDropMenu.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | 5570B2161B22A2A300A97B4B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5570B2151B22A2A300A97B4B /* AppDelegate.swift */; };
11 | 5570B2181B22A2A300A97B4B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5570B2171B22A2A300A97B4B /* ViewController.swift */; };
12 | 5570B21B1B22A2A300A97B4B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5570B2191B22A2A300A97B4B /* Main.storyboard */; };
13 | 5570B21D1B22A2A300A97B4B /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5570B21C1B22A2A300A97B4B /* Images.xcassets */; };
14 | 5570B2201B22A2A300A97B4B /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5570B21E1B22A2A300A97B4B /* LaunchScreen.xib */; };
15 | 5570B2361B22A30700A97B4B /* DKDropMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5570B2351B22A30700A97B4B /* DKDropMenu.swift */; };
16 | /* End PBXBuildFile section */
17 |
18 | /* Begin PBXFileReference section */
19 | 5570B2101B22A2A300A97B4B /* DKDropMenu.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DKDropMenu.app; sourceTree = BUILT_PRODUCTS_DIR; };
20 | 5570B2141B22A2A300A97B4B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
21 | 5570B2151B22A2A300A97B4B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
22 | 5570B2171B22A2A300A97B4B /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
23 | 5570B21A1B22A2A300A97B4B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
24 | 5570B21C1B22A2A300A97B4B /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; };
25 | 5570B21F1B22A2A300A97B4B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; };
26 | 5570B2351B22A30700A97B4B /* DKDropMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DKDropMenu.swift; sourceTree = ""; };
27 | /* End PBXFileReference section */
28 |
29 | /* Begin PBXFrameworksBuildPhase section */
30 | 5570B20D1B22A2A300A97B4B /* Frameworks */ = {
31 | isa = PBXFrameworksBuildPhase;
32 | buildActionMask = 2147483647;
33 | files = (
34 | );
35 | runOnlyForDeploymentPostprocessing = 0;
36 | };
37 | /* End PBXFrameworksBuildPhase section */
38 |
39 | /* Begin PBXGroup section */
40 | 5570B2071B22A2A300A97B4B = {
41 | isa = PBXGroup;
42 | children = (
43 | 5570B2351B22A30700A97B4B /* DKDropMenu.swift */,
44 | 5570B2121B22A2A300A97B4B /* DKDropMenu */,
45 | 5570B2111B22A2A300A97B4B /* Products */,
46 | );
47 | sourceTree = "";
48 | };
49 | 5570B2111B22A2A300A97B4B /* Products */ = {
50 | isa = PBXGroup;
51 | children = (
52 | 5570B2101B22A2A300A97B4B /* DKDropMenu.app */,
53 | );
54 | name = Products;
55 | sourceTree = "";
56 | };
57 | 5570B2121B22A2A300A97B4B /* DKDropMenu */ = {
58 | isa = PBXGroup;
59 | children = (
60 | 5570B2151B22A2A300A97B4B /* AppDelegate.swift */,
61 | 5570B2171B22A2A300A97B4B /* ViewController.swift */,
62 | 5570B2191B22A2A300A97B4B /* Main.storyboard */,
63 | 5570B21C1B22A2A300A97B4B /* Images.xcassets */,
64 | 5570B21E1B22A2A300A97B4B /* LaunchScreen.xib */,
65 | 5570B2131B22A2A300A97B4B /* Supporting Files */,
66 | );
67 | path = DKDropMenu;
68 | sourceTree = "";
69 | };
70 | 5570B2131B22A2A300A97B4B /* Supporting Files */ = {
71 | isa = PBXGroup;
72 | children = (
73 | 5570B2141B22A2A300A97B4B /* Info.plist */,
74 | );
75 | name = "Supporting Files";
76 | sourceTree = "";
77 | };
78 | /* End PBXGroup section */
79 |
80 | /* Begin PBXNativeTarget section */
81 | 5570B20F1B22A2A300A97B4B /* DKDropMenu */ = {
82 | isa = PBXNativeTarget;
83 | buildConfigurationList = 5570B22F1B22A2A300A97B4B /* Build configuration list for PBXNativeTarget "DKDropMenu" */;
84 | buildPhases = (
85 | 5570B20C1B22A2A300A97B4B /* Sources */,
86 | 5570B20D1B22A2A300A97B4B /* Frameworks */,
87 | 5570B20E1B22A2A300A97B4B /* Resources */,
88 | );
89 | buildRules = (
90 | );
91 | dependencies = (
92 | );
93 | name = DKDropMenu;
94 | productName = DKDropMenu;
95 | productReference = 5570B2101B22A2A300A97B4B /* DKDropMenu.app */;
96 | productType = "com.apple.product-type.application";
97 | };
98 | /* End PBXNativeTarget section */
99 |
100 | /* Begin PBXProject section */
101 | 5570B2081B22A2A300A97B4B /* Project object */ = {
102 | isa = PBXProject;
103 | attributes = {
104 | LastSwiftMigration = 0710;
105 | LastSwiftUpdateCheck = 0710;
106 | LastUpgradeCheck = 0800;
107 | ORGANIZATIONNAME = "Oak Snow Consulting";
108 | TargetAttributes = {
109 | 5570B20F1B22A2A300A97B4B = {
110 | CreatedOnToolsVersion = 6.3.2;
111 | LastSwiftMigration = 0900;
112 | };
113 | };
114 | };
115 | buildConfigurationList = 5570B20B1B22A2A300A97B4B /* Build configuration list for PBXProject "DKDropMenu" */;
116 | compatibilityVersion = "Xcode 3.2";
117 | developmentRegion = English;
118 | hasScannedForEncodings = 0;
119 | knownRegions = (
120 | en,
121 | Base,
122 | );
123 | mainGroup = 5570B2071B22A2A300A97B4B;
124 | productRefGroup = 5570B2111B22A2A300A97B4B /* Products */;
125 | projectDirPath = "";
126 | projectRoot = "";
127 | targets = (
128 | 5570B20F1B22A2A300A97B4B /* DKDropMenu */,
129 | );
130 | };
131 | /* End PBXProject section */
132 |
133 | /* Begin PBXResourcesBuildPhase section */
134 | 5570B20E1B22A2A300A97B4B /* Resources */ = {
135 | isa = PBXResourcesBuildPhase;
136 | buildActionMask = 2147483647;
137 | files = (
138 | 5570B21B1B22A2A300A97B4B /* Main.storyboard in Resources */,
139 | 5570B2201B22A2A300A97B4B /* LaunchScreen.xib in Resources */,
140 | 5570B21D1B22A2A300A97B4B /* Images.xcassets in Resources */,
141 | );
142 | runOnlyForDeploymentPostprocessing = 0;
143 | };
144 | /* End PBXResourcesBuildPhase section */
145 |
146 | /* Begin PBXSourcesBuildPhase section */
147 | 5570B20C1B22A2A300A97B4B /* Sources */ = {
148 | isa = PBXSourcesBuildPhase;
149 | buildActionMask = 2147483647;
150 | files = (
151 | 5570B2361B22A30700A97B4B /* DKDropMenu.swift in Sources */,
152 | 5570B2181B22A2A300A97B4B /* ViewController.swift in Sources */,
153 | 5570B2161B22A2A300A97B4B /* AppDelegate.swift in Sources */,
154 | );
155 | runOnlyForDeploymentPostprocessing = 0;
156 | };
157 | /* End PBXSourcesBuildPhase section */
158 |
159 | /* Begin PBXVariantGroup section */
160 | 5570B2191B22A2A300A97B4B /* Main.storyboard */ = {
161 | isa = PBXVariantGroup;
162 | children = (
163 | 5570B21A1B22A2A300A97B4B /* Base */,
164 | );
165 | name = Main.storyboard;
166 | sourceTree = "";
167 | };
168 | 5570B21E1B22A2A300A97B4B /* LaunchScreen.xib */ = {
169 | isa = PBXVariantGroup;
170 | children = (
171 | 5570B21F1B22A2A300A97B4B /* Base */,
172 | );
173 | name = LaunchScreen.xib;
174 | sourceTree = "";
175 | };
176 | /* End PBXVariantGroup section */
177 |
178 | /* Begin XCBuildConfiguration section */
179 | 5570B22D1B22A2A300A97B4B /* Debug */ = {
180 | isa = XCBuildConfiguration;
181 | buildSettings = {
182 | ALWAYS_SEARCH_USER_PATHS = NO;
183 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
184 | CLANG_CXX_LIBRARY = "libc++";
185 | CLANG_ENABLE_MODULES = YES;
186 | CLANG_ENABLE_OBJC_ARC = YES;
187 | CLANG_WARN_BOOL_CONVERSION = YES;
188 | CLANG_WARN_CONSTANT_CONVERSION = YES;
189 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
190 | CLANG_WARN_EMPTY_BODY = YES;
191 | CLANG_WARN_ENUM_CONVERSION = YES;
192 | CLANG_WARN_INFINITE_RECURSION = YES;
193 | CLANG_WARN_INT_CONVERSION = YES;
194 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
195 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
196 | CLANG_WARN_UNREACHABLE_CODE = YES;
197 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
198 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
199 | COPY_PHASE_STRIP = NO;
200 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
201 | ENABLE_STRICT_OBJC_MSGSEND = YES;
202 | ENABLE_TESTABILITY = YES;
203 | GCC_C_LANGUAGE_STANDARD = gnu99;
204 | GCC_DYNAMIC_NO_PIC = NO;
205 | GCC_NO_COMMON_BLOCKS = YES;
206 | GCC_OPTIMIZATION_LEVEL = 0;
207 | GCC_PREPROCESSOR_DEFINITIONS = (
208 | "DEBUG=1",
209 | "$(inherited)",
210 | );
211 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
212 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
213 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
214 | GCC_WARN_UNDECLARED_SELECTOR = YES;
215 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
216 | GCC_WARN_UNUSED_FUNCTION = YES;
217 | GCC_WARN_UNUSED_VARIABLE = YES;
218 | IPHONEOS_DEPLOYMENT_TARGET = 8.3;
219 | MTL_ENABLE_DEBUG_INFO = YES;
220 | ONLY_ACTIVE_ARCH = YES;
221 | SDKROOT = iphoneos;
222 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
223 | TARGETED_DEVICE_FAMILY = "1,2";
224 | };
225 | name = Debug;
226 | };
227 | 5570B22E1B22A2A300A97B4B /* Release */ = {
228 | isa = XCBuildConfiguration;
229 | buildSettings = {
230 | ALWAYS_SEARCH_USER_PATHS = NO;
231 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
232 | CLANG_CXX_LIBRARY = "libc++";
233 | CLANG_ENABLE_MODULES = YES;
234 | CLANG_ENABLE_OBJC_ARC = YES;
235 | CLANG_WARN_BOOL_CONVERSION = YES;
236 | CLANG_WARN_CONSTANT_CONVERSION = YES;
237 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
238 | CLANG_WARN_EMPTY_BODY = YES;
239 | CLANG_WARN_ENUM_CONVERSION = YES;
240 | CLANG_WARN_INFINITE_RECURSION = YES;
241 | CLANG_WARN_INT_CONVERSION = YES;
242 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
243 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
244 | CLANG_WARN_UNREACHABLE_CODE = YES;
245 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
246 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
247 | COPY_PHASE_STRIP = NO;
248 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
249 | ENABLE_NS_ASSERTIONS = NO;
250 | ENABLE_STRICT_OBJC_MSGSEND = YES;
251 | GCC_C_LANGUAGE_STANDARD = gnu99;
252 | GCC_NO_COMMON_BLOCKS = YES;
253 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
254 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
255 | GCC_WARN_UNDECLARED_SELECTOR = YES;
256 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
257 | GCC_WARN_UNUSED_FUNCTION = YES;
258 | GCC_WARN_UNUSED_VARIABLE = YES;
259 | IPHONEOS_DEPLOYMENT_TARGET = 8.3;
260 | MTL_ENABLE_DEBUG_INFO = NO;
261 | SDKROOT = iphoneos;
262 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
263 | TARGETED_DEVICE_FAMILY = "1,2";
264 | VALIDATE_PRODUCT = YES;
265 | };
266 | name = Release;
267 | };
268 | 5570B2301B22A2A300A97B4B /* Debug */ = {
269 | isa = XCBuildConfiguration;
270 | buildSettings = {
271 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
272 | INFOPLIST_FILE = DKDropMenu/Info.plist;
273 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
274 | PRODUCT_BUNDLE_IDENTIFIER = "com.oaksnow.$(PRODUCT_NAME:rfc1034identifier)";
275 | PRODUCT_NAME = "$(TARGET_NAME)";
276 | SWIFT_SWIFT3_OBJC_INFERENCE = Default;
277 | SWIFT_VERSION = 4.0;
278 | };
279 | name = Debug;
280 | };
281 | 5570B2311B22A2A300A97B4B /* Release */ = {
282 | isa = XCBuildConfiguration;
283 | buildSettings = {
284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
285 | INFOPLIST_FILE = DKDropMenu/Info.plist;
286 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
287 | PRODUCT_BUNDLE_IDENTIFIER = "com.oaksnow.$(PRODUCT_NAME:rfc1034identifier)";
288 | PRODUCT_NAME = "$(TARGET_NAME)";
289 | SWIFT_SWIFT3_OBJC_INFERENCE = Default;
290 | SWIFT_VERSION = 4.0;
291 | };
292 | name = Release;
293 | };
294 | /* End XCBuildConfiguration section */
295 |
296 | /* Begin XCConfigurationList section */
297 | 5570B20B1B22A2A300A97B4B /* Build configuration list for PBXProject "DKDropMenu" */ = {
298 | isa = XCConfigurationList;
299 | buildConfigurations = (
300 | 5570B22D1B22A2A300A97B4B /* Debug */,
301 | 5570B22E1B22A2A300A97B4B /* Release */,
302 | );
303 | defaultConfigurationIsVisible = 0;
304 | defaultConfigurationName = Release;
305 | };
306 | 5570B22F1B22A2A300A97B4B /* Build configuration list for PBXNativeTarget "DKDropMenu" */ = {
307 | isa = XCConfigurationList;
308 | buildConfigurations = (
309 | 5570B2301B22A2A300A97B4B /* Debug */,
310 | 5570B2311B22A2A300A97B4B /* Release */,
311 | );
312 | defaultConfigurationIsVisible = 0;
313 | defaultConfigurationName = Release;
314 | };
315 | /* End XCConfigurationList section */
316 | };
317 | rootObject = 5570B2081B22A2A300A97B4B /* Project object */;
318 | }
319 |
--------------------------------------------------------------------------------