Skip to content

Commit

Permalink
Sample code in readme. Added new public init for swift.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrolfe committed Dec 18, 2017
1 parent 3e10b24 commit df6693c
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 36 deletions.
2 changes: 2 additions & 0 deletions PARTagPicker.xcodeproj/project.pbxproj
Expand Up @@ -427,6 +427,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = PARTagPicker/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -438,6 +439,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = PARTagPicker/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
1 change: 1 addition & 0 deletions PARTagPicker/Classes/PARTagColorReference.h
Expand Up @@ -12,6 +12,7 @@
@interface PARTagColorReference : NSObject

- (instancetype)initWithDefaultColors;
- (instancetype)init;

@property (nonatomic, strong) UIColor *chosenTagBackgroundColor;
@property (nonatomic, strong) UIColor *chosenTagTextColor;
Expand Down
5 changes: 5 additions & 0 deletions PARTagPicker/Classes/PARTagColorReference.m
Expand Up @@ -10,6 +10,11 @@

@implementation PARTagColorReference

- (instancetype)init {
self = [self initWithDefaultColors];
return self;
}

- (instancetype)initWithDefaultColors {
self = [super init];
if (self) {
Expand Down
22 changes: 13 additions & 9 deletions PARTagPicker/Resources/PARTagCollectionViewCell.xib
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<deployment version="1792" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand All @@ -12,15 +16,16 @@
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="100" height="27"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="NRo-lh-92a" customClass="PARBackspaceTextField">
<rect key="frame" x="100" y="0.0" width="0.0" height="27"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="tintColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<color key="tintColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" id="saD-cA-4KF"/>
</constraints>
<color key="textColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
<connections>
Expand All @@ -34,7 +39,7 @@
<constraint firstAttribute="width" constant="54" id="jZ6-8A-A90"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
<variation key="default">
<mask key="constraints">
Expand All @@ -43,7 +48,6 @@
</variation>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<constraints>
<constraint firstItem="GLK-rW-vew" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" constant="16" id="0uA-1R-p0T"/>
Expand Down
18 changes: 11 additions & 7 deletions PARTagPicker/Resources/PARTagPickerViewController.xib
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<deployment version="1792" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="PARTagPickerViewController">
Expand All @@ -21,7 +25,7 @@
<subviews>
<collectionView multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="F5J-vl-Z6E" userLabel="Available Collection View">
<rect key="frame" x="0.0" y="39" width="320" height="0.0"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" id="82s-Oo-GA9"/>
</constraints>
Expand All @@ -38,7 +42,7 @@
</collectionView>
<collectionView multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="none" translatesAutoresizingMaskIntoConstraints="NO" id="0nj-WZ-ytQ" userLabel="Chosen Collection View">
<rect key="frame" x="0.0" y="0.0" width="320" height="39"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="height" constant="39" id="Xb2-ht-unZ"/>
</constraints>
Expand All @@ -54,7 +58,7 @@
</connections>
</collectionView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="F5J-vl-Z6E" secondAttribute="bottom" id="3Ut-dO-s07"/>
<constraint firstItem="F5J-vl-Z6E" firstAttribute="leading" secondItem="0nj-WZ-ytQ" secondAttribute="leading" id="5XA-zR-eeh"/>
Expand Down
15 changes: 10 additions & 5 deletions PARTagPicker/Resources/PARTextFieldCollectionViewCell.xib
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14E46" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<deployment version="1792" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand All @@ -11,10 +16,11 @@
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="100" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="mqc-63-Kb0" customClass="PARBackspaceTextField">
<rect key="frame" x="0.0" y="0.0" width="100" height="30"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="100" id="ImX-YK-VBW"/>
</constraints>
Expand All @@ -31,7 +37,6 @@
</connections>
</textField>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<constraints>
<constraint firstItem="mqc-63-Kb0" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" id="ilq-Hu-Fe1"/>
Expand Down
34 changes: 19 additions & 15 deletions PARTagPicker/ViewController.xib
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10116" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<deployment version="1792" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ViewController">
Expand All @@ -12,45 +16,45 @@
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NX5-xi-CxW">
<rect key="frame" x="255" y="285" width="89" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="NX5-xi-CxW">
<rect key="frame" x="143" y="318.5" width="89" height="30"/>
<state key="normal" title="Hide All Tags">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="hideAllTags:" destination="-1" eventType="touchUpInside" id="XYX-bs-HSw"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rFt-4m-Gtp">
<rect key="frame" x="216" y="323" width="168" height="30"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rFt-4m-Gtp">
<rect key="frame" x="104.5" y="356.5" width="166" height="30"/>
<state key="normal" title="Show Chosen Tags Only">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showChosenTagsOnly:" destination="-1" eventType="touchUpInside" id="amt-30-Kjw"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="G0u-nI-QOF">
<rect key="frame" x="252" y="247" width="96" height="30"/>
<rect key="frame" x="140" y="280.5" width="95" height="30"/>
<state key="normal" title="Show All Tags">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="showAllTags:" destination="-1" eventType="touchUpInside" id="ukf-JI-Xxk"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="EqL-Sp-xD2">
<rect key="frame" x="275" y="361" width="49" height="30"/>
<rect key="frame" x="163" y="394.5" width="49" height="30"/>
<state key="normal" title="Add All"/>
<connections>
<action selector="addAll:" destination="-1" eventType="touchUpInside" id="BpP-4K-3BA"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="S9A-aV-qQP">
<rect key="frame" x="271.5" y="399" width="57" height="30"/>
<rect key="frame" x="159" y="432.5" width="57" height="30"/>
<state key="normal" title="Clear All"/>
<connections>
<action selector="clearAll:" destination="-1" eventType="touchUpInside" id="7PB-ru-o2e"/>
Expand Down
43 changes: 43 additions & 0 deletions README.md
Expand Up @@ -33,6 +33,49 @@ The basic setup is to create an instance of `PARTagPickerViewController`, add it

The tags are passed in as `NSString` objects in an array. Anytime you change the `allTags` array, any existing `chosenTags` are updated to use references to the new strings if they contain a match in the updated array. Otherwise they continue to point to the old strings.

### Swift
```swift
override func viewDidLoad() {
super.viewDidLoad()
// Add the controller and view.
let tagController = PARTagPickerViewController()
addChildViewController(tagController)
tagController.view.frame = CGRect(x: 0, y: 64, width: view.bounds.width, height: COLLECTION_VIEW_HEIGHT)
view.addSubview(tagController.view)
tagController.didMove(toParentViewController: self)

// Customize appearance and data.
tagController.delegate = self
tagController.allTags = ["one fish","two fish"," red fish", "blue fish"]
tagController.chosenTags = ["with a fox", "in a box", "anywhere"]
tagController.allowsNewTags = true
tagController.view.backgroundColor = .orange
let colors = PARTagColorReference()
colors.highlightedTagTextColor = .white
colors.highlightedTagBackgroundColor = .blue
tagController.tagColorRef = colors
}

func tagPicker(_ tagPicker: PARTagPickerViewController!, visibilityChangedTo state: PARTagPickerVisibilityState) {
var newHeight: CGFloat = 0
if state == .topAndBottom {
newHeight = 2 * COLLECTION_VIEW_HEIGHT
} else if state == .topOnly {
newHeight = COLLECTION_VIEW_HEIGHT
}

var frame = tagPicker.view.frame
frame.size.height = newHeight

UIView.animate(withDuration: 0.3) {
tagPicker.view.frame = frame
}
}
```

### Obj-C
See example with `pod try PARTagPicker` or check the example view controller here: https://github.com/paulrolfe/PARTagPicker/blob/master/PARTagPicker/ViewController.m

## Options
* You can customize colors using a PARTagColorReference object.
* You can allow new tags with `allowsNewTags` boolean property on the controller.
Expand Down

0 comments on commit df6693c

Please sign in to comment.