Skip to content

Commit 700af01

Browse files
committed
Merge pull request #110 from AnyRead/master
1 parent 36ccea6 commit 700af01

18 files changed

+266
-225
lines changed

BTNavigationDropdownMenu.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
1212
s.social_media_url = "https://www.facebook.com/phambatho"
1313
s.platform = :ios, '8.0'
1414
s.source = { :git => "https://github.com/PhamBaTho/BTNavigationDropdownMenu.git", :tag => s.version.to_s }
15-
s.source_files = "Source/**/*.swift"
15+
s.source_files = "Source/**/**/*.swift"
1616
s.resources = "Source/*.bundle"
1717
s.requires_arc = true
1818
end

Demo/Demo.xcodeproj/project.pbxproj

+51-97
Large diffs are not rendered by default.
File renamed without changes.

README.md

+34-41
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
<!--[![Build Status](https://travis-ci.org/PhamBaTho/BTNavigationDropdownMenu.svg?branch=master)](https://travis-ci.org/PhamBaTho/BTNavigationDropdownMenu)-->
77

88
## Introduction:
9-
The elegant dropdown menu, written in **Swift**, appears underneath navigation bar to display a list of related items when a user click on the navigation title.
9+
This elegant **Swift** dropdown menu appears underneath the navigation bar to display a list of related items when a user clicks on the navigation title.
1010

1111
![alt tag](https://github.com/PhamBaTho/BTNavigationDropdownMenu/blob/master/Assets/Demo.gif)
1212

1313
## Installation:
14-
**BTNavigationDropdownMenu** is available through [CocoaPods](http://cocoapods.org). To install
15-
it, simply add the following line to your Podfile:
14+
**BTNavigationDropdownMenu** is available through [CocoaPods](http://cocoapods.org). To install it, simply add the following line to your Podfile:
1615

1716
```ruby
1817
use_frameworks!
@@ -22,33 +21,25 @@ Go ahead and **import** BTNavigationDropdownMenu into your own Swift files
2221
```swift
2322
import BTNavigationDropdownMenu
2423
```
25-
Note: This library mainly supports for **Xcode 7, Swift 2.2** and embedded frameworks.
26-
27-
⚡⚡️⚡ **Swift 3.0 supporting** ⚡⚡⚡
28-
29-
If you would like to use Swift 3.0, you can use these lines of code in your Podfile:
30-
31-
```ruby
32-
pod 'BTNavigationDropdownMenu', :git => 'https://github.com/PhamBaTho/BTNavigationDropdownMenu.git', :branch => 'swift-3.0'
33-
```
24+
Note: This library supports for **Xcode 8.3 Swift 3.1** and embedded frameworks.
3425

3526
## Usage:
36-
### Instantiating
37-
Start by creating an Array that contains strings as **elements of dropdown list**:
27+
### Instantiate
28+
Start by creating an Array that contains strings as **elements of a dropdown list**:
3829
```swift
3930
let items = ["Most Popular", "Latest", "Trending", "Nearest", "Top Picks"]
4031
```
4132
Create a **new instance** of BTNavigationDropdownMenu:
4233
```swift
4334
let menuView = BTNavigationDropdownMenu(navigationController: self.navigationController, containerView: self.navigationController!.view, title: "Dropdown Menu", items: items)
4435
```
45-
or just simple like this:
36+
or like this:
4637
```swift
4738
let menuView = BTNavigationDropdownMenu(title: items[0], items: items)
4839
```
49-
By default, `navigationController` is the top most navigation controller and `containerView` is keyWindow.
40+
By default, `navigationController` is the topmost navigation controller and `containerView` is keyWindow.
5041

51-
(`keyWindow` is recommended for `containerView` because in this way, the black overlay can cover the whole screen. But in some cases, `keyWindow` doesn't work properly, like using with side menu, (e.g. SWRevealViewController), the dropdown menu didn't move along with their parent view controller or navigation controller. To resolve this issue, you can use `self.navigationController!.view` instead.)
42+
(`keyWindow` is recommended for `containerView` because the black overlay can cover the whole screen. In some cases, `keyWindow` doesn't work properly, like using with side menu, (e.g. SWRevealViewController), the dropdown menu doesn't move along with the parent view or navigation controller. To workaround this issue, you can use `self.navigationController!.view`.)
5243

5344
Set **title of navigation bar** as menuView:
5445
```swift
@@ -61,56 +52,58 @@ menuView.didSelectItemAtIndexHandler = {[weak self] (indexPath: Int) -> () in
6152
self.selectedCellLabel.text = items[indexPath]
6253
}
6354
```
64-
Use `menuView.show()` or `menuView.hide()` if you want to show or hide dropdown menu manually.
55+
`menuView.show()` or `menuView.hide()` to show or hide dropdown menu manually.
6556

66-
Use `menuView.toggle()` to toogle dropdown menu shown/hide.
57+
`menuView.toggle()` to toogle dropdown menu shown/hide.
6758

68-
Use `menuView.isShown` (Boolean type) property to check showing state of dropdown menu.
59+
`menuView.isShown` (Boolean type) property to check showing state of dropdown menu.
6960

70-
Use `menuView.updateItems(items: [AnyObject])` to update items in dropdown menu if needed.
61+
`menuView.updateItems(items: [AnyObject])` to update items in dropdown menu.
7162

7263
### Customization
73-
Once you have assigned the items and frame for dropdown menu, you can custom the look and the feel of menu. You can override these properties for your favor:
64+
First, assign the items and frame for the dropdown menu. Then, customize the look and feel of the menu by overriding these properties:
65+
66+
`cellHeight` **- Cell height** *Default is 50*
7467

75-
`cellHeight` **- The height of the cell.** *Default is 50*
68+
`cellBackgroundColor` **- Cell background color** *Default is whiteColor()*
7669

77-
`cellBackgroundColor` **- The color of the cell background.** *Default is whiteColor()*
70+
`cellSeparatorColor` **- Cell separator color** *Default is darkGrayColor()*
7871

79-
`cellSeparatorColor` **- The color of the cell separator.** *Default is darkGrayColor()*
72+
`cellTextLabelColor` **- Text color inside of the cell** *Default is darkGrayColor()*
8073

81-
`cellTextLabelColor` **- The color of the text inside cell.** *Default is darkGrayColor()*
74+
`cellTextLabelFont` **- Font inside the cell** *Default is HelveticaNeue-Bold, size 17*
8275

83-
`cellTextLabelFont` **- The font of the text inside cell.** *Default is HelveticaNeue-Bold, size 17*
76+
`navigationBarTitleFont` **- Navigation bar title font** *Default is HelveticaNeue-Bold, size 17*
8477

85-
`navigationBarTitleFont` **- The font of the navigation bar title.** *Default is HelveticaNeue-Bold, size 17*
78+
`cellTextLabelAlignment` **- Text alignment inside of the cell** *Default is .Left*
8679

87-
`cellTextLabelAlignment` **- The alignment of the text inside cell.** *Default is .Left*
80+
`cellSelectionColor` **- Selected color of the cell** *Default is lightGrayColor()*
8881

89-
`cellSelectionColor` **- The color of the cell when the cell is selected.** *Default is lightGrayColor()*
82+
`checkMarkImage` **- Checkmark icon for the cell.**
9083

91-
`checkMarkImage` **- The checkmark icon of the cell.**
84+
`animationDuration` **- Animation duration for showing/hiding of the menu** *Default is 0.5s*
9285

93-
`animationDuration` **- The animation duration of showing/hiding menu.** *Default is 0.5s*
86+
`arrowImage` **- Arrow next to the navigation title**
9487

95-
`arrowImage` **- The arrow next to navigation title**
88+
`arrowPadding` **- Padding between the navigation title and arrow.** *Default is 15*
9689

97-
`arrowPadding` **- The padding between navigation title and arrow.** *Default is 15*
90+
`maskBackgroundColor` **- Mask layer color** *Default is blackColor()*
9891

99-
`maskBackgroundColor` **- The color of the mask layer.** *Default is blackColor()*
92+
`maskBackgroundOpacity` **- Opacity of the mask layer** *Default is 0.3*
10093

101-
`maskBackgroundOpacity` **- The opacity of the mask layer.** *Default is 0.3*
94+
`menuTitleColor` **- Title color displayed in the menu.** *Default is lightGrayColor()*
10295

103-
`shouldKeepSelectedCellColor` **- The boolean value that decides if selected color of cell is visible when the menu is shown.** *Default is false*
96+
`shouldKeepSelectedCellColor` **- Selected cell color visibility when menu is shown** *Default is false*
10497

105-
`shouldChangeTitleText` **- The boolean value that decides if you want to change the title text when a cell is selected.** *Default is true*
98+
`shouldChangeTitleText` **- Ability to change the selected title text** *Default is true*
10699

107-
`selectedCellTextLabelColor` **- The color of the selected cell text label.** *Default is darkGrayColor()*
100+
`selectedCellTextLabelColor` **- Selected cell text label color** *Default is darkGrayColor()*
108101

109-
`arrowTintColor` **- The tint color of the arrow.** *Default is whiteColor()*
102+
`arrowTintColor` **- Tint color of the arrow.** *Default is whiteColor()*
110103

111104
## Requirement
112105
- iOS 8.0+ (CocoaPods with Swift support will only work on iOS 8.0+. Alternatively, you will have to import library manually to your project)
113-
- Xcode 7.0+, Swift 2.0+
106+
- Xcode 8.0+, Swift 3.0+
114107

115108
## Changelog
116109
See the [CHANGELOG](https://github.com/PhamBaTho/BTNavigationDropdownMenu/blob/master/CHANGELOG.md) for details

Source/BTNavigationDropdownMenu.swift

+24-19
Original file line numberDiff line numberDiff line change
@@ -237,29 +237,34 @@ open class BTNavigationDropdownMenu: UIView {
237237
required public init?(coder aDecoder: NSCoder) {
238238
fatalError("init(coder:) has not been implemented")
239239
}
240-
241-
242-
/// Legacy init converted as a convenience initializer to call the default init
243-
///
244-
/// - Parameters:
245-
/// - navigationController: navigation Controller
246-
/// - containerView: container view
247-
/// - title: raw title to display
248-
/// - items: items to select
240+
241+
/**
242+
243+
Legacy init converted as a convenience initializer to call the default init
244+
245+
- parameters:
246+
- navigationController: The present and visible navigation controller.
247+
- containerView: The container view. Default is keyWindow.
248+
- title: A string to define title to be displayed.
249+
- items: The array of items to select
250+
*/
249251
public convenience init(navigationController: UINavigationController? = nil, containerView: UIView = UIApplication.shared.keyWindow!, title: String, items: [String]) {
250252

251253
self.init(navigationController: navigationController, containerView: containerView, title: BTTitle.title(title), items: items)
252-
253254
}
254255

255-
256-
/// Default init. This will allow the user to define a raw title or a index where the user can pre-define the index that is selected. This is specially handy for when it's necessary to restore from a saved state
257-
///
258-
/// - Parameters:
259-
/// - navigationController: navigation controllre
260-
/// - containerView: container view
261-
/// - title: enum with the title to display
262-
/// - items: items to select
256+
/**
257+
258+
Default init. This will allow the user to define a string or a index where the user can
259+
pre-define as a default selected. This is specially handy for when it's necessary to
260+
restore from a saved state
261+
262+
- parameters:
263+
- navigationController: The present and visible navigation controller.
264+
- containerView: The container view. Default is keyWindow.
265+
- title: An enum to define title to be displayed, can be a string or index of items.
266+
- items: The array of items to select
267+
*/
263268
public init(navigationController: UINavigationController? = nil, containerView: UIView = UIApplication.shared.keyWindow!, title: BTTitle, items: [String]) {
264269
// Key window
265270
guard let window = UIApplication.shared.keyWindow else {
@@ -500,7 +505,7 @@ open class BTNavigationDropdownMenu: UIView {
500505
func rotateArrow() {
501506
UIView.animate(withDuration: self.configuration.animationDuration, animations: {[weak self] () -> () in
502507
if let selfie = self {
503-
selfie.menuArrow.transform = selfie.menuArrow.transform.rotated(by: 180 * CGFloat(M_PI/180))
508+
selfie.menuArrow.transform = selfie.menuArrow.transform.rotated(by: 180 * CGFloat(Double.pi/180))
504509
}
505510
})
506511
}

Source/BTTitle.swift

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
//
22
// BTTitle.swift
3-
// Demo
43
//
5-
// Created by Manuel Gomes on 06/02/2017.
6-
// Copyright © 2017 PHAM BA THO. All rights reserved.
4+
// Copyright (c) 2017 PHAM BA THO ([email protected]). All rights reserved.
75
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
823

924
import Foundation
1025

26+
/**
1127

12-
/// Allows to define the type of title that I want. A default title or just onde of the items
13-
///
14-
/// - title: default title
15-
/// - index: index to fetch from the items
16-
public enum BTTitle{
28+
An enum to set type of navigation title.
1729

30+
- parameters:
31+
- title: Set navigation title as string.
32+
- index: Set navigation title as index of items.
33+
Items is defined from BTNavigationDropdownMenu initialization.
34+
*/
35+
public enum BTTitle {
1836
case title(String)
1937
case index(Int)
20-
2138
}

Source/BTConfiguration.swift Source/Internal/BTConfiguration.swift

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
//
22
// BTConfiguration.swift
3-
// Demo
43
//
5-
// Created by Manuel Gomes on 06/02/2017.
6-
// Copyright © 2017 PHAM BA THO. All rights reserved.
4+
// Copyright (c) 2017 PHAM BA THO ([email protected]). All rights reserved.
75
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
823

924
import UIKit
1025

11-
// MARK: BTConfiguration
1226
final class BTConfiguration {
1327
var menuTitleColor: UIColor?
1428
var cellHeight: CGFloat!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// BTTableCellContentView.swift
3+
//
4+
// Copyright (c) 2017 PHAM BA THO ([email protected]). All rights reserved.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
24+
import UIKit
25+
26+
// Content view of table view cell
27+
class BTTableCellContentView: UIView {
28+
var separatorColor: UIColor = UIColor.black
29+
30+
override init(frame: CGRect) {
31+
super.init(frame: frame)
32+
33+
self.initialize()
34+
}
35+
36+
required init?(coder aDecoder: NSCoder) {
37+
super.init(coder: aDecoder)
38+
39+
self.initialize()
40+
}
41+
42+
func initialize() {
43+
self.backgroundColor = UIColor.clear
44+
}
45+
46+
override func draw(_ rect: CGRect) {
47+
super.draw(rect)
48+
let context = UIGraphicsGetCurrentContext()
49+
50+
// Set separator color of dropdown menu based on barStyle
51+
context?.setStrokeColor(self.separatorColor.cgColor)
52+
context?.setLineWidth(1)
53+
context?.move(to: CGPoint(x: 0, y: self.bounds.size.height))
54+
context?.addLine(to: CGPoint(x: self.bounds.size.width, y: self.bounds.size.height))
55+
context?.strokePath()
56+
}
57+
}

Source/BTTableView.swift Source/Internal/Table View/BTTableView.swift

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
//
22
// BTTableView.swift
3-
// Demo
43
//
5-
// Created by Manuel Gomes on 06/02/2017.
6-
// Copyright © 2017 PHAM BA THO. All rights reserved.
4+
// Copyright (c) 2017 PHAM BA THO ([email protected]). All rights reserved.
75
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files (the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions:
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
823

924
import UIKit
1025

11-
// MARK: Table View
1226
class BTTableView: UITableView, UITableViewDelegate, UITableViewDataSource {
1327

1428
// Public properties

0 commit comments

Comments
 (0)