Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for multiple lines label in cells. #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ class ViewController: UIViewController {
// You can also use localizationKeysDataSource instead. Check the docs.
chooseDropDown.dataSource = [
"Lorem ipsum dolor",
"sit amet consectetur",
"sit amet consectetur sit amet consectetur sit amet consectetur sit amet consectetur sit amet consectetur",
// long string for testing multi-line support in tableview cell.
"cadipisci en..."
]

Expand Down
26 changes: 17 additions & 9 deletions DropDown/resources/DropDownCell.xib
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
<?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">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" 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"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</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="8" y="0.0" width="304" height="44"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="44" id="Hy3-Wl-MDp"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<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"/>
</label>
</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="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 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 firstItem="dhL-pA-i6q" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="qo1-5r-HsS"/>
<constraint firstAttribute="bottom" secondItem="dhL-pA-i6q" secondAttribute="bottom" id="wRT-h8-gtn"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="optionLabel" destination="dhL-pA-i6q" id="1GT-db-EaA"/>
</connections>
<point key="canvasLocation" x="34" y="54"/>
</view>
</objects>
</document>
10 changes: 10 additions & 0 deletions DropDown/src/DropDown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ extension DropDown: UITableViewDataSource, UITableViewDelegate {

cell.optionLabel.textColor = textColor
cell.optionLabel.font = textFont
cell.optionLabel.numberOfLines = 0
cell.optionLabel.lineBreakMode = .byWordWrapping
cell.selectedBackgroundColor = selectionBackgroundColor

if let cellConfiguration = cellConfiguration {
Expand All @@ -1029,6 +1031,14 @@ extension DropDown: UITableViewDataSource, UITableViewDelegate {
customCellConfiguration?(index, dataSource[index], cell)
}

public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}

public func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return cellHeight
}

public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.isSelected = selectedRowIndices.first{ $0 == (indexPath as NSIndexPath).row } != nil
}
Expand Down