Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## `develop`

* Drop Class Name Prefixes
* Add an easy to use `OptionPickerControl` that displays a `UIPickerView` with given options

## v1.5.0

* Swift 4.0
Expand Down
53 changes: 44 additions & 9 deletions Example/ExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ import ICInputAccessory

class ExampleViewController: UITableViewController {

private let types: [UIView.Type] = [
private let showcases: [UIView.Type] = [
KeyboardDismissTextField.self,
TokenField.self,
CustomizedTokenField.self
CustomizedTokenField.self,
OptionPickerControl<Language>.self
]

private lazy var languagePicker: OptionPickerControl<Language> = {
let picker = OptionPickerControl<Language>()
picker.options += Language.availableLanguages.map(Option.init(_:))
picker.addTarget(self, action: .updateLanguage, for: .valueChanged)
return picker
}()

private lazy var flipButton: UIButton = {
let _button = UIButton(type: .system)
_button.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 88)
Expand All @@ -52,41 +60,45 @@ class ExampleViewController: UITableViewController {

// MARK: - UIViewController

override func loadView() {
super.loadView()
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = 44
tableView.register(ExampleCell.self, forCellReuseIdentifier: String(describing: ExampleCell.self))
tableView.tableFooterView = flipButton
tableView.tableFooterView?.isUserInteractionEnabled = true
view.addSubview(languagePicker)
}

// MARK: - UITableViewDataSource

override func numberOfSections(in tableView: UITableView) -> Int {
return types.count
return showcases.count
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch types[section] {
switch showcases[section] {
case is KeyboardDismissTextField.Type:
return "Dismiss Keyboard"
case is TokenField.Type:
return "Text Field with Tokens"
case is CustomizedTokenField.Type:
return "Customize Token Field"
case is OptionPickerControl<Language>.Type:
return "Option Picker Control"
default:
return ""
}
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ExampleCell.self), for: indexPath)
cell.accessoryType = .none

switch types[indexPath.section] {
switch showcases[indexPath.section] {
case let type as KeyboardDismissTextField.Type:
let textField = type.init()
textField.leftViewMode = .always
Expand All @@ -107,6 +119,11 @@ class ExampleViewController: UITableViewController {
container.addSubview(tokenField)
(cell as? ExampleCell)?.showcase = container

case is OptionPickerControl<Language>.Type:
(cell as? ExampleCell)?.showcase = nil
cell.textLabel?.text = languagePicker.selectedOption.title
cell.accessoryType = .disclosureIndicator

default:
break
}
Expand All @@ -116,12 +133,25 @@ class ExampleViewController: UITableViewController {
// MARK: - UITableViewDelegate

override func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
return types[indexPath.section] == CustomizedTokenField.self
switch showcases[indexPath.section] {
case is CustomizedTokenField.Type:
return true
case is OptionPickerControl<Language>.Type:
return true
default:
return false
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if types[indexPath.section] == CustomizedTokenField.self {
switch showcases[indexPath.section] {
case is CustomizedTokenField.Type:
present(UINavigationController(rootViewController: CustomizedTokenViewController()), animated: true, completion: nil)
case is OptionPickerControl<Language>.Type:
tableView.deselectRow(at: indexPath, animated: true)
languagePicker.becomeFirstResponder()
default:
break
}
}

Expand All @@ -134,6 +164,10 @@ class ExampleViewController: UITableViewController {
}
}

@objc fileprivate func updateLanguage(_ sender: UIControl) {
tableView.reloadData()
}

}


Expand All @@ -142,4 +176,5 @@ class ExampleViewController: UITableViewController {

private extension Selector {
static let showStoryboard = #selector(ExampleViewController.showStoryboard(_:))
static let updateLanguage = #selector(ExampleViewController.updateLanguage(_:))
}
58 changes: 58 additions & 0 deletions Example/Language.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Language.swift
// Example
//
// Created by Ben on 20/01/2018.
// Copyright © 2018 bcylin.
//
// 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.
//

import Foundation
import ICInputAccessory

enum Language: String, OptionDescriptive {

case english
case french
case german
case japanese
case mandarin
case spanish

static var availableLanguages: [Language] = [
.english,
.french,
.german,
.japanese,
.mandarin,
.spanish
]

// MARK: - OptionDescriptive

var title: String {
return rawValue.capitalized
}

static var titleForOptionalValue: String {
return "(Optional)"
}

}
6 changes: 5 additions & 1 deletion ICInputAccessory.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ Pod::Spec.new do |s|
s.source = { git: "https://github.com/polydice/ICInputAccessory.git", tag: "v#{s.version}" }
s.requires_arc = true

s.default_subspecs = "KeyboardDismissTextField", "TokenField"
s.default_subspecs = "KeyboardDismissTextField", "OptionPickerControl", "TokenField"

s.subspec "KeyboardDismissTextField" do |sp|
sp.source_files = "Source/KeyboardDismissTextField/*.swift"
sp.resources = "Source/KeyboardDismissTextField/*.xcassets"
end

s.subspec "OptionPickerControl" do |sp|
sp.source_files = "Source/OptionPickerControl/*.swift"
end

s.subspec "TokenField" do |sp|
sp.source_files = "Source/TokenField/*.swift"
end
Expand Down
24 changes: 24 additions & 0 deletions ICInputAccessory.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
B528196D1C9035BE007D01D5 /* InsetLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52819691C9035BE007D01D5 /* InsetLabel.swift */; };
B528196E1C9035BE007D01D5 /* Token.swift in Sources */ = {isa = PBXBuildFile; fileRef = B528196A1C9035BE007D01D5 /* Token.swift */; };
B528196F1C9035BE007D01D5 /* TokenField.swift in Sources */ = {isa = PBXBuildFile; fileRef = B528196B1C9035BE007D01D5 /* TokenField.swift */; };
B52ADB1920132F0C00D96B87 /* Option.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52ADB1720132F0C00D96B87 /* Option.swift */; };
B52ADB1A20132F0C00D96B87 /* OptionPickerControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52ADB1820132F0C00D96B87 /* OptionPickerControl.swift */; };
B52ADB1C201332E400D96B87 /* Language.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52ADB1B201332E400D96B87 /* Language.swift */; };
B52ADB1F201485B800D96B87 /* OptionPickerControlUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B52ADB1D201485A700D96B87 /* OptionPickerControlUITests.swift */; };
B533768B1F4436D000230739 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B533768A1F4436D000230739 /* AppDelegate.swift */; };
B53376921F4436D000230739 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B53376911F4436D000230739 /* Assets.xcassets */; };
B53376951F4436D000230739 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B53376931F4436D000230739 /* LaunchScreen.storyboard */; };
Expand Down Expand Up @@ -70,6 +74,10 @@
B52819691C9035BE007D01D5 /* InsetLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InsetLabel.swift; path = Source/TokenField/InsetLabel.swift; sourceTree = SOURCE_ROOT; };
B528196A1C9035BE007D01D5 /* Token.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Token.swift; path = Source/TokenField/Token.swift; sourceTree = SOURCE_ROOT; };
B528196B1C9035BE007D01D5 /* TokenField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TokenField.swift; path = Source/TokenField/TokenField.swift; sourceTree = SOURCE_ROOT; };
B52ADB1720132F0C00D96B87 /* Option.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Option.swift; path = Source/OptionPickerControl/Option.swift; sourceTree = SOURCE_ROOT; };
B52ADB1820132F0C00D96B87 /* OptionPickerControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OptionPickerControl.swift; path = Source/OptionPickerControl/OptionPickerControl.swift; sourceTree = SOURCE_ROOT; };
B52ADB1B201332E400D96B87 /* Language.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Language.swift; sourceTree = "<group>"; };
B52ADB1D201485A700D96B87 /* OptionPickerControlUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OptionPickerControlUITests.swift; path = ICInputAccessoryUITests/OptionPickerControlUITests.swift; sourceTree = SOURCE_ROOT; };
B53376881F4436D000230739 /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
B533768A1F4436D000230739 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
B53376911F4436D000230739 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -148,6 +156,15 @@
name = TokenField;
sourceTree = "<group>";
};
B52ADB1220132EEF00D96B87 /* OptionPickerControl */ = {
isa = PBXGroup;
children = (
B52ADB1720132F0C00D96B87 /* Option.swift */,
B52ADB1820132F0C00D96B87 /* OptionPickerControl.swift */,
);
name = OptionPickerControl;
sourceTree = "<group>";
};
B53376891F4436D000230739 /* Example */ = {
isa = PBXGroup;
children = (
Expand All @@ -158,6 +175,7 @@
B53376AF1F44387000230739 /* ExampleCell.swift */,
B53376B01F44387000230739 /* ExampleViewController.swift */,
B53376961F4436D000230739 /* Info.plist */,
B52ADB1B201332E400D96B87 /* Language.swift */,
B53376931F4436D000230739 /* LaunchScreen.storyboard */,
B53376B11F44387000230739 /* Main.storyboard */,
B53376B21F44387000230739 /* StoryboardViewController.swift */,
Expand All @@ -170,6 +188,7 @@
children = (
B53376A11F4436D000230739 /* Info.plist */,
B53376A91F4437D900230739 /* KeyboardDismissTextFieldUITests.swift */,
B52ADB1D201485A700D96B87 /* OptionPickerControlUITests.swift */,
B53376AA1F4437D900230739 /* TokenFieldUITests.swift */,
);
name = ICInputAccessoryUITests;
Expand Down Expand Up @@ -202,6 +221,7 @@
isa = PBXGroup;
children = (
B52819671C90358C007D01D5 /* KeyboardDismissAccessory */,
B52ADB1220132EEF00D96B87 /* OptionPickerControl */,
B52819701C9035C3007D01D5 /* TokenField */,
B56BC42D1C89A7EA00C20AD6 /* ICInputAccessory.h */,
B548C5AC1C8D69A5009D5AEE /* Images.xcassets */,
Expand Down Expand Up @@ -410,6 +430,7 @@
B53376B41F44387000230739 /* CustomizedTokenViewController.swift in Sources */,
B53376B51F44387000230739 /* ExampleCell.swift in Sources */,
B53376B61F44387000230739 /* ExampleViewController.swift in Sources */,
B52ADB1C201332E400D96B87 /* Language.swift in Sources */,
B53376B81F44387000230739 /* StoryboardViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -419,6 +440,7 @@
buildActionMask = 2147483647;
files = (
B53376AB1F4437D900230739 /* KeyboardDismissTextFieldUITests.swift in Sources */,
B52ADB1F201485B800D96B87 /* OptionPickerControlUITests.swift in Sources */,
B53376AC1F4437D900230739 /* TokenFieldUITests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -431,6 +453,8 @@
B528196D1C9035BE007D01D5 /* InsetLabel.swift in Sources */,
B56BC4361C89A8D800C20AD6 /* KeyboardDismissAccessoryView.swift in Sources */,
B548C5EE1C8EB9E2009D5AEE /* KeyboardDismissTextField.swift in Sources */,
B52ADB1920132F0C00D96B87 /* Option.swift in Sources */,
B52ADB1A20132F0C00D96B87 /* OptionPickerControl.swift in Sources */,
B528196E1C9035BE007D01D5 /* Token.swift in Sources */,
B528196F1C9035BE007D01D5 /* TokenField.swift in Sources */,
);
Expand Down
64 changes: 64 additions & 0 deletions ICInputAccessoryUITests/OptionPickerControlUITests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// OptionPickerControlUITests.swift
// ICInputAccessoryUITests
//
// Created by Ben on 21/01/2018.
// Copyright © 2018 bcylin.
//
// 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.
//

import XCTest

final class OptionPickerControlUITests: XCTestCase {

private lazy var app = XCUIApplication()

override func setUp() {
super.setUp()
continueAfterFailure = false
XCUIApplication().launch()
}

func testOptionSelection() {
app.tables.staticTexts["(Optional)"].tap()
let picker = app.pickerWheels.element

picker.adjust(toPickerWheelValue: "English")
XCTAssert(app.tables.staticTexts["English"].exists)

picker.adjust(toPickerWheelValue: "French")
XCTAssert(app.tables.staticTexts["French"].exists)

picker.adjust(toPickerWheelValue: "German")
XCTAssert(app.tables.staticTexts["German"].exists)

picker.adjust(toPickerWheelValue: "Japanese")
XCTAssert(app.tables.staticTexts["Japanese"].exists)

picker.adjust(toPickerWheelValue: "Mandarin")
XCTAssert(app.tables.staticTexts["Mandarin"].exists)

picker.adjust(toPickerWheelValue: "Spanish")
XCTAssert(app.tables.staticTexts["Spanish"].exists)

app.toolbars.buttons["Done"].tap()
}

}
Loading