Skip to content

Commit

Permalink
support custom tabbar feature
Browse files Browse the repository at this point in the history
  • Loading branch information
hongxinhope committed Aug 14, 2017
1 parent 5e1b2f2 commit 5173a08
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion DropdownMenu/DropdownMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
import UIKit

public protocol DropdownMenuDelegate: class {
func dropdownMenu(_ dropdownMenu: DropdownMenu, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
func dropdownMenu(_ dropdownMenu: DropdownMenu, cellForRowAt indexPath: IndexPath) -> UITableViewCell?
func dropdownMenu(_ dropdownMenu: DropdownMenu, didSelectRowAt indexPath: IndexPath)
func dropdownMenu(_ dropdownMenu: DropdownMenu, shouldUpdateSelectionAt indexPath: IndexPath) -> Bool
func dropdownMenuCancel(_ dropdownMenu: DropdownMenu)
func dropdownMenuWillDismiss(_ dropdownMenu: DropdownMenu)
func dropdownMenuWillShow(_ dropdownMenu: DropdownMenu)
}

public extension DropdownMenuDelegate {
func dropdownMenu(_ dropdownMenu: DropdownMenu, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { }
func dropdownMenu(_ dropdownMenu: DropdownMenu, cellForRowAt indexPath: IndexPath) -> UITableViewCell? { return nil }
func dropdownMenu(_ dropdownMenu: DropdownMenu, didSelectRowAt indexPath: IndexPath) { }
func dropdownMenu(_ dropdownMenu: DropdownMenu, shouldUpdateSelectionAt indexPath: IndexPath) -> Bool { return true }
func dropdownMenuCancel(_ dropdownMenu: DropdownMenu) { }
func dropdownMenuWillDismiss(_ dropdownMenu: DropdownMenu) { }
func dropdownMenuWillShow(_ dropdownMenu: DropdownMenu) { }
Expand Down Expand Up @@ -63,6 +67,13 @@ open class DropdownMenu: UIView {
tableView.backgroundColor = tableViewBackgroundColor
}
}
open var separatorStyle: UITableViewCellSeparatorStyle = .singleLine {
didSet {
if let tableView = tableView {
tableView.separatorStyle = separatorStyle
}
}
}
open var tableViewSeperatorColor = UIColor(red: 217.0/255.0, green: 217.0/255.0, blue: 217.0/255.0, alpha: 1.0) {
didSet {
tableView.separatorColor = tableViewSeperatorColor
Expand Down Expand Up @@ -167,6 +178,7 @@ open class DropdownMenu: UIView {
}

tableView = UITableView(frame: CGRect.zero, style: .grouped)
tableView.separatorStyle = separatorStyle
tableView?.delegate = self
tableView?.dataSource = self
addSubview(tableView)
Expand Down Expand Up @@ -275,6 +287,10 @@ extension DropdownMenu: UITableViewDataSource {
return sections[section].items.count
}

public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
delegate?.dropdownMenu(self, willDisplay: cell, forRowAt: indexPath)
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let customCell = delegate?.dropdownMenu(self, cellForRowAt: indexPath) {
return customCell
Expand Down Expand Up @@ -335,7 +351,8 @@ extension DropdownMenu: UITableViewDelegate {
}

public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if displaySelected {
let shouldUpdateSelection = delegate?.dropdownMenu(self, shouldUpdateSelectionAt: indexPath) ?? true
if displaySelected && shouldUpdateSelection {
let item = sections[indexPath.section].items[indexPath.row]
if item.accessoryImage == nil {
let previousSelectedcell = tableView.cellForRow(at: selectedIndexPath)
Expand Down

0 comments on commit 5173a08

Please sign in to comment.