Skip to content

Commit

Permalink
Added full implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
k-o-d-e-n committed Jun 28, 2020
1 parent 56a8558 commit 7fd3fed
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 79 deletions.
16 changes: 3 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ DerivedData
# Bundler
.bundle

# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Note: if you ignore the Pods directory, make sure to uncomment
# `pod install` in .travis.yml
#
# Pods/
.build
Example/Pods
Example/PopUpButton.xcworkspace
16 changes: 16 additions & 0 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PODS:
- PopUpButton (1.0)

DEPENDENCIES:
- PopUpButton (from `../`)

EXTERNAL SOURCES:
PopUpButton:
:path: "../"

SPEC CHECKSUMS:
PopUpButton: 1769a8faf9471c97f2ab08e5505204dec96bf362

PODFILE CHECKSUM: 94c6f2f9fa5f0b0f0753affc63203fb233199fc8

COCOAPODS: 1.9.1
23 changes: 17 additions & 6 deletions Example/PopUpButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/* Begin PBXFileReference section */
46DD1F481A35D3CFA543CD9F /* Pods-PopUpButton_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PopUpButton_Example.debug.xcconfig"; path = "Target Support Files/Pods-PopUpButton_Example/Pods-PopUpButton_Example.debug.xcconfig"; sourceTree = "<group>"; };
4FB91DB217779AF312B33EF0 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
4FB91DB217779AF312B33EF0 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
5A9A564EEAAAC24E3DF5D2F3 /* Pods_PopUpButton_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PopUpButton_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD01AFB9204008FA782 /* PopUpButton_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PopUpButton_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -44,8 +44,9 @@
72FDD88FC65B1EFF4E6ACFED /* Pods-PopUpButton_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PopUpButton_Example.release.xcconfig"; path = "Target Support Files/Pods-PopUpButton_Example/Pods-PopUpButton_Example.release.xcconfig"; sourceTree = "<group>"; };
8562D8FCA12F848DBE73DA0E /* Pods_PopUpButton_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_PopUpButton_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
85B0F23707BD3717EA9E1077 /* Pods-PopUpButton_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PopUpButton_Tests.release.xcconfig"; path = "Target Support Files/Pods-PopUpButton_Tests/Pods-PopUpButton_Tests.release.xcconfig"; sourceTree = "<group>"; };
ADC0F68BFE7A5F552F8D6859 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; name = README.md; path = ../README.md; sourceTree = "<group>"; };
B648F96F4D695103A6E1EFA6 /* PopUpButton.podspec */ = {isa = PBXFileReference; includeInIndex = 1; name = PopUpButton.podspec; path = ../PopUpButton.podspec; sourceTree = "<group>"; };
A4143B3024A8B505003F87E5 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Package.swift; path = ../Package.swift; sourceTree = "<group>"; };
ADC0F68BFE7A5F552F8D6859 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
B648F96F4D695103A6E1EFA6 /* PopUpButton.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = PopUpButton.podspec; path = ../PopUpButton.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
BA6433CCBA30BCC96456F3C6 /* Pods-PopUpButton_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PopUpButton_Tests.debug.xcconfig"; path = "Target Support Files/Pods-PopUpButton_Tests/Pods-PopUpButton_Tests.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -77,13 +78,13 @@
BA6433CCBA30BCC96456F3C6 /* Pods-PopUpButton_Tests.debug.xcconfig */,
85B0F23707BD3717EA9E1077 /* Pods-PopUpButton_Tests.release.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
607FACC71AFB9204008FA782 = {
isa = PBXGroup;
children = (
A4143B3024A8B505003F87E5 /* Package.swift */,
607FACF51AFB993E008FA782 /* Podspec Metadata */,
607FACD21AFB9204008FA782 /* Example for PopUpButton */,
607FACE81AFB9204008FA782 /* Tests */,
Expand Down Expand Up @@ -171,7 +172,7 @@
607FACCC1AFB9204008FA782 /* Sources */,
607FACCD1AFB9204008FA782 /* Frameworks */,
607FACCE1AFB9204008FA782 /* Resources */,
45D39B95642EB71472F18797 /* [CP] Embed Pods Frameworks */,
0AD7934B83730B604AC6CF56 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -217,6 +218,7 @@
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 39RU298KG9;
LastSwiftMigration = 0900;
TestTargetID = 607FACCF1AFB9204008FA782;
};
Expand All @@ -227,6 +229,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -262,7 +265,7 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
45D39B95642EB71472F18797 /* [CP] Embed Pods Frameworks */ = {
0AD7934B83730B604AC6CF56 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
Expand Down Expand Up @@ -479,6 +482,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = PopUpButton/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Expand All @@ -494,6 +498,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = PopUpButton/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Expand All @@ -507,6 +512,8 @@
isa = XCBuildConfiguration;
baseConfigurationReference = BA6433CCBA30BCC96456F3C6 /* Pods-PopUpButton_Tests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 39RU298KG9;
FRAMEWORK_SEARCH_PATHS = (
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -516,6 +523,7 @@
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -529,11 +537,14 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 85B0F23707BD3717EA9E1077 /* Pods-PopUpButton_Tests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
DEVELOPMENT_TEAM = 39RU298KG9;
FRAMEWORK_SEARCH_PATHS = (
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "PopUpButton_Example.app"
BlueprintName = "PopUpButton_Example"
ReferencedContainer = "container:PopUpButton.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -54,23 +62,11 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "PopUpButton_Example.app"
BlueprintName = "PopUpButton_Example"
ReferencedContainer = "container:PopUpButton.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand All @@ -87,8 +83,6 @@
ReferencedContainer = "container:PopUpButton.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
30 changes: 26 additions & 4 deletions Example/PopUpButton/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,40 @@
//

import UIKit
import PopUpButton

class ViewController: UIViewController {
var buttons: [PopUpButton] = []

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

let items: [PopUpButton.Item] = (0..<20).map { i in
PopUpButton.Item(title: "\(Character(Unicode.Scalar(0x1F600 + i)!)) Item \(i)")
}

buttons = (0..<4).map({ i -> PopUpButton in
let button = PopUpButton(items: items)
button.backgroundColor = .black
button.layer.cornerRadius = 12
button.currentIndex = Double(i + 1) / 4.0 > 0.5 ? 5 : 15
button.addTarget(self, action: #selector(popUpButtonTouchUpInside), for: .valueChanged)
view.addSubview(button)
return button
})
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

buttons[0].frame = CGRect(x: 50, y: 100, width: 130, height: 44)
buttons[1].frame = CGRect(x: view.bounds.width - 50 - 130, y: 100, width: 130, height: 44)
buttons[2].frame = CGRect(x: 50, y: view.bounds.height - 100 - 44, width: 130, height: 44)
buttons[3].frame = CGRect(x: view.bounds.width - 50 - 130, y: view.bounds.height - 100 - 44, width: 130, height: 44)
}

@objc func popUpButtonTouchUpInside(_ button: PopUpButton) {
print("Selected item at index", button.currentIndex)
}
}

20 changes: 20 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// swift-tools-version:5.1
import PackageDescription

let package = Package(
name: "PopUpButton",
platforms: [.iOS(.v11)],
products: [
.library(
name: "PopUpButton",
targets: ["PopUpButton"]
)
],
dependencies: [],
targets: [
.target(
name: "PopUpButton",
dependencies: []
)
]
)
40 changes: 7 additions & 33 deletions PopUpButton.podspec
Original file line number Diff line number Diff line change
@@ -1,42 +1,16 @@
#
# Be sure to run `pod lib lint PopUpButton.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = 'PopUpButton'
s.version = '0.1.0'
s.summary = 'A short description of PopUpButton.'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!

s.version = '1.0'
s.summary = 'A control for selecting an item from a list.'
s.description = <<-DESC
TODO: Add long description of the pod here.
"A control for selecting an item from a list. In other words, single motion `NSPopUpButton` for iOS."
DESC

s.homepage = 'https://github.com/k-o-d-e-n/PopUpButton'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.screenshots = 'https://raw.githubusercontent.com/k-o-d-e-n/PopUpButton/master/Resources/demo.gif'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'k-o-d-e-n' => '[email protected]' }
s.source = { :git => 'https://github.com/k-o-d-e-n/PopUpButton.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

s.ios.deployment_target = '8.0'

s.source_files = 'PopUpButton/Classes/**/*'

# s.resource_bundles = {
# 'PopUpButton' => ['PopUpButton/Assets/*.png']
# }

# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
s.social_media_url = 'https://twitter.com/K_o_D_e_N'
s.ios.deployment_target = '11.0'
s.source_files = 'Sources/PopUpButton/**/*'
end
Empty file removed PopUpButton/Classes/.gitkeep
Empty file.
Empty file.
47 changes: 40 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,58 @@
# PopUpButton

[![CI Status](https://img.shields.io/travis/k-o-d-e-n/PopUpButton.svg?style=flat)](https://travis-ci.org/k-o-d-e-n/PopUpButton)
[![Version](https://img.shields.io/cocoapods/v/PopUpButton.svg?style=flat)](https://cocoapods.org/pods/PopUpButton)
[![License](https://img.shields.io/cocoapods/l/PopUpButton.svg?style=flat)](https://cocoapods.org/pods/PopUpButton)
[![Platform](https://img.shields.io/cocoapods/p/PopUpButton.svg?style=flat)](https://cocoapods.org/pods/PopUpButton)
A control for selecting an item from a list. In other words, single motion `NSPopUpButton` for iOS.

```swift
public final class PopUpButton : UIControl {

public var itemsColor: UIColor? { get set }

public var selectedItemColor: UIColor? { get set }

public var coverBackgroundColor: UIColor? { get set }

public var anchor: Anchor { get set }

public var items: [Item] { get set }

public var currentIndex: Int { get set }

public struct Item {
public let title: String
}

public enum Anchor {
case window
case superview
}
}

```

## Example

To run the example project, clone the repo, and run `pod install` from the Example directory first.
<p align="center">
<img src="Resources/demo.gif">
</p>

## Requirements

Swift 5+

## Installation

PopUpButton is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:
Cocoapods

```ruby
pod 'PopUpButton'
```

Swift Package Manager

```
.package(url: "https://github.com/k-o-d-e-n/PopUpButton.git", .branch("master"))
```

## Author

k-o-d-e-n, [email protected]
Expand Down
Binary file added Resources/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Loading

0 comments on commit 7fd3fed

Please sign in to comment.