Skip to content

Commit

Permalink
Merge pull request #19 from tichise/design
Browse files Browse the repository at this point in the history
add argument for separatorStyle
  • Loading branch information
tichise authored Sep 17, 2019
2 parents 6ba0a6a + dcad9eb commit 32524e2
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 18 deletions.
2 changes: 1 addition & 1 deletion PopOverMenu.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PopOverMenu'
s.version = '2.5.3'
s.version = '2.5.4'
s.license = 'MIT'
s.summary = 'PopOverMenu is a PopOver style menu.'
s.homepage = 'https://github.com/tichise/PopOverMenu'
Expand Down
4 changes: 2 additions & 2 deletions Sample/Sample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Sample/Pods-Sample-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-Sample/Pods-Sample-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/PopOverMenu/PopOverMenu.framework",
);
name = "[CP] Embed Pods Frameworks";
Expand All @@ -331,7 +331,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Sample/Pods-Sample-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Sample/Pods-Sample-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
D8F8D2B702D51C2DA9AB421F /* [CP] Check Pods Manifest.lock */ = {
Expand Down
78 changes: 78 additions & 0 deletions Sample/Sample.xcodeproj/xcshareddata/xcschemes/Sample.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "798268F91F1F269B0090613B"
BuildableName = "Sample.app"
BlueprintName = "Sample"
ReferencedContainer = "container:Sample.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "798268F91F1F269B0090613B"
BuildableName = "Sample.app"
BlueprintName = "Sample"
ReferencedContainer = "container:Sample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "798268F91F1F269B0090613B"
BuildableName = "Sample.app"
BlueprintName = "Sample"
ReferencedContainer = "container:Sample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
12 changes: 7 additions & 5 deletions Sample/Sample/RootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import PopOverMenu

class RootViewController: UITableViewController, UIAdaptivePresentationControllerDelegate {

let separatorStyle: UITableViewCell.SeparatorStyle = .singleLine

var popOverViewController: PopOverViewController?
var section1 = ["Int Array", "String Array", "Int Array(All selectable)"]
var section2 = ["Enum", "Enum(All selectable)"]
Expand Down Expand Up @@ -102,7 +104,7 @@ class RootViewController: UITableViewController, UIAdaptivePresentationControlle
let titles = [ "Menu1", "Menu2", "Menu3"]
let keys = [1, 2, 3]

self.popOverViewController?.setArrayForView(delegate: self, view: view, titles: titles, keys: keys, defaultKey: selectedIntKey) { (key, index) in
self.popOverViewController?.setArrayForView(delegate: self, view: view, titles: titles, keys: keys, defaultKey: selectedIntKey, separatorStyle: separatorStyle) { (key, index) in

self.selectedIntKey = key

Expand All @@ -120,7 +122,7 @@ class RootViewController: UITableViewController, UIAdaptivePresentationControlle
let titles = [ "Menu1", "Menu2", "Menu3"]
let keys = ["menu1", "menu2", "menu3"]

self.popOverViewController?.setArrayForView(delegate: self, view: view, titles: titles, keys: keys, defaultKey: selectedStringKey) { (key, index) in
self.popOverViewController?.setArrayForView(delegate: self, view: view, titles: titles, keys: keys, defaultKey: selectedStringKey, separatorStyle: separatorStyle) { (key, index) in

self.selectedStringKey = key

Expand All @@ -138,7 +140,7 @@ class RootViewController: UITableViewController, UIAdaptivePresentationControlle
let titles = ["Menu1", "Menu2", "Menu3"]
let keys = [1, 2, 3]

self.popOverViewController?.setArrayForView(delegate: self, view: view, titles: titles, keys: keys, defaultKey: selectedIntKey, allName: allName, onSelected: { (key, index) in
self.popOverViewController?.setArrayForView(delegate: self, view: view, titles: titles, keys: keys, defaultKey: selectedIntKey, allName: allName, separatorStyle: separatorStyle, onSelected: { (key, index) in
self.selectedIntKey = key

print("key is \(String(describing: key)) , index is \(index) ")
Expand All @@ -154,7 +156,7 @@ class RootViewController: UITableViewController, UIAdaptivePresentationControlle
func openEnumMenu(view :UIView) {
self.popOverViewController = PopOverViewController.instantiate()

self.popOverViewController?.setEnumForView(delegate: self, view: view, enumType: FoodName.self, defaultEnum: selectedFoodName, onSelected: { (key, index) in
self.popOverViewController?.setEnumForView(delegate: self, view: view, enumType: FoodName.self, defaultEnum: selectedFoodName, separatorStyle: separatorStyle, onSelected: { (key, index) in

self.selectedFoodName = key

Expand All @@ -172,7 +174,7 @@ class RootViewController: UITableViewController, UIAdaptivePresentationControlle
func openEnumMenu(view :UIView, allName: String) {
self.popOverViewController = PopOverViewController.instantiate()

self.popOverViewController?.setEnumForView(delegate: self, view: view, enumType: FoodName.self, defaultEnum: selectedFoodName, allName: allName, onSelected: { (key, index) in
self.popOverViewController?.setEnumForView(delegate: self, view: view, enumType: FoodName.self, defaultEnum: selectedFoodName, allName: allName, separatorStyle: separatorStyle, onSelected: { (key, index) in
print("key is \(String(describing: key)) , index is \(index) ")

if index == 0 {
Expand Down
4 changes: 3 additions & 1 deletion Sample/Sample/SampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import PopOverMenu

class SampleViewController: UIViewController, UIAdaptivePresentationControllerDelegate {

let separatorStyle: UITableViewCell.SeparatorStyle = .singleLine

var popOverViewController: PopOverViewController?

@IBOutlet weak var textLabel:UILabel?
Expand All @@ -31,7 +33,7 @@ class SampleViewController: UIViewController, UIAdaptivePresentationControllerDe
let titles = ["Menu1", "Menu2", "Menu3"]
let descriptions = ["description1", "description2", "description3"]

self.popOverViewController?.setArrayForBarButtonItem(delegate: self, barButtonItem: sender, titles: titles, descriptions: descriptions, separatorStyle: .none) { (selectRow) in
self.popOverViewController?.setArrayForBarButtonItem(delegate: self, barButtonItem: sender, titles: titles, descriptions: descriptions, separatorStyle: separatorStyle) { (selectRow) in
self.textLabel?.text = String(selectRow)
}

Expand Down
9 changes: 4 additions & 5 deletions Sources/PopOverViewController+Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

extension PopOverViewController {

open func setArrayForView<T: Comparable>(delegate:UIAdaptivePresentationControllerDelegate, view: UIView, titles: [String]?, keys: [T]?, defaultKey: T?, allName: String, onSelected: @escaping (_ key:T?, _ index: Int) -> ()) {
open func setArrayForView<T: Comparable>(delegate:UIAdaptivePresentationControllerDelegate, view: UIView, titles: [String]?, keys: [T]?, defaultKey: T?, allName: String, separatorStyle: UITableViewCell.SeparatorStyle, onSelected: @escaping (_ key:T?, _ index: Int) -> ()) {

guard let titles = titles else {
return
Expand All @@ -20,12 +20,12 @@ extension PopOverViewController {
mutableTitles.insert(allName, at: 0)
mutableKeys.insert(nil, at: 0)

setArrayForView(delegate: delegate, view: view, titles: mutableTitles, keys: mutableKeys, defaultKey: defaultKey) { (key, index) in
setArrayForView(delegate: delegate, view: view, titles: mutableTitles, keys: mutableKeys, defaultKey: defaultKey, separatorStyle: separatorStyle) { (key, index) in
onSelected(key, index)
}
}

open func setArrayForView<T: Comparable>(delegate:UIAdaptivePresentationControllerDelegate, view: UIView, titles: [String]?, keys: [T?]?, defaultKey: T?, onSelected: @escaping (_ key: T?, _ index: Int) -> ()) {
open func setArrayForView<T: Comparable>(delegate:UIAdaptivePresentationControllerDelegate, view: UIView, titles: [String]?, keys: [T?]?, defaultKey: T?, separatorStyle: UITableViewCell.SeparatorStyle, onSelected: @escaping (_ key: T?, _ index: Int) -> ()) {

guard let titles = titles else {
return
Expand All @@ -36,7 +36,7 @@ extension PopOverViewController {
}

self.set(showsVerticalScrollIndicator: true)
self.set(separatorStyle: .singleLine)
self.set(separatorStyle: separatorStyle)
self.set(titles: titles)
self.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.any

Expand All @@ -50,7 +50,6 @@ extension PopOverViewController {
}
}


self.popoverPresentationController?.sourceView = view
self.popoverPresentationController?.sourceRect = view.frame

Expand Down
8 changes: 4 additions & 4 deletions Sources/PopOverViewController+Enum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

extension PopOverViewController {

open func setEnumForView<T: CaseIterable & RawRepresentable & Hashable>(delegate: UIAdaptivePresentationControllerDelegate, view: UIView, enumType: T.Type, defaultEnum: T?, allName: String, onSelected: @escaping (_ key: T?, _ index: Int) -> ()) {
open func setEnumForView<T: CaseIterable & RawRepresentable & Hashable>(delegate: UIAdaptivePresentationControllerDelegate, view: UIView, enumType: T.Type, defaultEnum: T?, allName: String, separatorStyle: UITableViewCell.SeparatorStyle, onSelected: @escaping (_ key: T?, _ index: Int) -> ()) {

let baseTitles = enumType.allCases.map{$0.rawValue}

Expand All @@ -19,7 +19,7 @@ extension PopOverViewController {
}

self.set(showsVerticalScrollIndicator: true)
self.set(separatorStyle: .singleLine)
self.set(separatorStyle: separatorStyle)
self.set(titles: titles)
self.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.any

Expand Down Expand Up @@ -49,7 +49,7 @@ extension PopOverViewController {
}
}

open func setEnumForView<T: CaseIterable & RawRepresentable & Hashable>(delegate: UIAdaptivePresentationControllerDelegate, view: UIView, enumType: T.Type, defaultEnum: T?, onSelected: @escaping (_ key: T?, _ index: Int) -> ()) {
open func setEnumForView<T: CaseIterable & RawRepresentable & Hashable>(delegate: UIAdaptivePresentationControllerDelegate, view: UIView, enumType: T.Type, defaultEnum: T?, separatorStyle: UITableViewCell.SeparatorStyle, onSelected: @escaping (_ key: T?, _ index: Int) -> ()) {

let baseTitles = enumType.allCases.map{$0.rawValue}

Expand All @@ -62,7 +62,7 @@ extension PopOverViewController {
}

self.set(showsVerticalScrollIndicator: true)
self.set(separatorStyle: .singleLine)
self.set(separatorStyle: separatorStyle)
self.set(titles: titles)
self.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.any

Expand Down
5 changes: 5 additions & 0 deletions Sources/PopOverViewController+TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ extension PopOverViewController {
cell.accessoryType = selectRow == indexPath.row ? UITableViewCell.AccessoryType.checkmark : UITableViewCell.AccessoryType.none
}

// Erase the last separator
if titles.count == indexPath.row + 1 {
cell.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: .greatestFiniteMagnitude)
}

return cell
}

Expand Down

0 comments on commit 32524e2

Please sign in to comment.