Skip to content
Open
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
33 changes: 28 additions & 5 deletions DropDown/resources/DropDownCell.xib
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="DropDownCell" customModule="DropDown_Demo" customModuleProvider="target">
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="DropDownCell" customModule="DropDown" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dhL-pA-i6q">
<rect key="frame" x="8" y="8" width="304" height="28"/>
<rect key="frame" x="44" y="8" width="232" height="28"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="TZd-Tb-H6m">
<rect key="frame" x="8" y="8" width="28" height="28"/>
<constraints>
<constraint firstAttribute="width" secondItem="TZd-Tb-H6m" secondAttribute="height" multiplier="1:1" id="MLn-0H-wIZ"/>
</constraints>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="URy-kk-P2w">
<rect key="frame" x="284" y="8" width="28" height="28"/>
<constraints>
<constraint firstAttribute="width" secondItem="URy-kk-P2w" secondAttribute="height" multiplier="1:1" id="et5-fg-9UR"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="dhL-pA-i6q" secondAttribute="trailing" constant="8" id="Phk-No-PFh"/>
<constraint firstItem="dhL-pA-i6q" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="8" id="QIg-6Z-lbJ"/>
<constraint firstAttribute="bottom" secondItem="TZd-Tb-H6m" secondAttribute="bottom" constant="8" id="5pu-58-VlT"/>
<constraint firstItem="dhL-pA-i6q" firstAttribute="leading" secondItem="TZd-Tb-H6m" secondAttribute="trailing" constant="8" id="AK6-f9-gsT"/>
<constraint firstItem="URy-kk-P2w" firstAttribute="leading" secondItem="dhL-pA-i6q" secondAttribute="trailing" constant="8" id="FZw-IF-6Xw"/>
<constraint firstItem="TZd-Tb-H6m" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="8" id="GQl-WH-rqe"/>
<constraint firstAttribute="trailing" secondItem="dhL-pA-i6q" secondAttribute="trailing" priority="999" constant="8" id="Phk-No-PFh"/>
<constraint firstItem="TZd-Tb-H6m" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="8" id="VVc-J7-zxP"/>
<constraint firstAttribute="bottom" secondItem="URy-kk-P2w" secondAttribute="bottom" constant="8" id="a0C-PH-gPA"/>
<constraint firstItem="URy-kk-P2w" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="8" id="kA1-Gw-Ep2"/>
<constraint firstItem="dhL-pA-i6q" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" priority="999" constant="8" id="n6s-fp-4gc"/>
<constraint firstItem="dhL-pA-i6q" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="8" id="qo1-5r-HsS"/>
<constraint firstAttribute="bottom" secondItem="dhL-pA-i6q" secondAttribute="bottom" constant="8" id="wRT-h8-gtn"/>
<constraint firstAttribute="trailing" secondItem="URy-kk-P2w" secondAttribute="trailing" constant="8" id="zXz-4R-Qek"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="leftIcon" destination="TZd-Tb-H6m" id="9n1-GE-gLB"/>
<outlet property="optionLabel" destination="dhL-pA-i6q" id="1GT-db-EaA"/>
<outlet property="rightIcon" destination="URy-kk-P2w" id="hdG-2P-V6y"/>
</connections>
</view>
</objects>
Expand Down
33 changes: 33 additions & 0 deletions DropDown/src/DropDown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ public final class DropDown: UIView {
case Bottom

}

/// The position of the icon for each drop down row.
public enum IconPosition {

/// The drop down icon will not show.
case None

/// The drop down icon will show on the left side of the row.
case Left

/// The drop down icon will show on the right side of the row.
case Right
}

//MARK: - Properties

Expand Down Expand Up @@ -126,6 +139,12 @@ public final class DropDown: UIView {
public var width: CGFloat? {
didSet { setNeedsUpdateConstraints() }
}

/// The position of the icon to be shown on the row.
public var iconPosition: IconPosition?

/// The icon image to be shown on the row.
public var icon: UIImage?

//MARK: Constraints
private var heightConstraint: NSLayoutConstraint!
Expand Down Expand Up @@ -909,7 +928,21 @@ extension DropDown: UITableViewDataSource, UITableViewDelegate {
cell.optionLabel.text = dataSource[index]
}

if let position = iconPosition, let iconImage = icon {
switch position {
case .None:
cell.setupNoIcon()
case .Left:
cell.setupLeftIcon(iconImage)
case .Right:
cell.setupRightIcon(iconImage)
}
} else {
cell.setupNoIcon()
}

customCellConfiguration?(index, dataSource[index], cell)


return cell
}
Expand Down
17 changes: 17 additions & 0 deletions DropDown/src/DropDownCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class DropDownCell: UITableViewCell {

//UI
@IBOutlet public weak var optionLabel: UILabel!
@IBOutlet public weak var leftIcon: UIImageView!
@IBOutlet public weak var rightIcon: UIImageView!

var selectedBackgroundColor: UIColor?

Expand Down Expand Up @@ -62,5 +64,20 @@ extension DropDownCell {
executeSelection()
}
}

public func setupNoIcon() {
leftIcon.removeFromSuperview()
rightIcon.removeFromSuperview()
}

public func setupLeftIcon(icon: UIImage) {
rightIcon.removeFromSuperview()
leftIcon.image = icon
}

public func setupRightIcon(icon: UIImage) {
leftIcon.removeFromSuperview()
rightIcon.image = icon
}

}