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
27 changes: 27 additions & 0 deletions PopOverMenuTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// PopOverMenuTableViewCell.swift
// PopOverMenu
//
// Created by ChanLi on 04/12/2020.
//

import UIKit

class PopOverMenuTableViewCell: UITableViewCell {

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}
override func layoutSubviews() {
super.layoutSubviews()
textLabel?.frame = CGRect.init(x: 0, y: textLabel?.frame.origin.y ?? 0, width: frame.width, height: textLabel?.frame.height ?? 0)
detailTextLabel?.frame = CGRect.init(x: 0, y: detailTextLabel?.frame.origin.y ?? 0, width: frame.size.width, height: detailTextLabel?.frame.size.height ?? 0)
}
}
6 changes: 5 additions & 1 deletion Sources/PopOverViewController+TableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ extension PopOverViewController {
if titles.count == indexPath.row + 1 {
cell.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: .greatestFiniteMagnitude)
}

cell.textLabel?.textAlignment = titleLabelTextAlignment
cell.detailTextLabel?.textAlignment = detailLabelTextAlignment
if let titleAndDetailLabelHandler = self.titleAndDetailLabel{
titleAndDetailLabelHandler(indexPath.row,cell.textLabel,cell.detailTextLabel)
}
return cell
}

Expand Down
13 changes: 9 additions & 4 deletions Sources/PopOverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
//

import Foundation

open class PopOverViewController: UITableViewController, UIAdaptivePresentationControllerDelegate {

var titles: [String] = []
var descriptions: [String]?
@objc open var completionHandler: ((_ selectRow: Int) -> Void)?
@objc open var titleAndDetailLabel: ((_ row:Int, _ titleLabel:UILabel?, _ detailLabel:UILabel?) -> Void)?
var selectRow:Int?
var titleLabelFont: UIFont = UIFont.systemFont(ofSize: 15)
var detailLabelFont: UIFont = UIFont.systemFont(ofSize: 10)
var cellHeight: CGFloat = 45

var storedSeparatorStyle: UITableViewCell.SeparatorStyle = UITableViewCell.SeparatorStyle.none
var storedShowsVerticalScrollIndicator = false

var titleLabelTextAlignment:NSTextAlignment = .natural
var detailLabelTextAlignment:NSTextAlignment = .natural
@objc public static func instantiate() -> PopOverViewController {
let storyboardsBundle = getStoryboardsBundle()
let storyboard:UIStoryboard = UIStoryboard(name: "PopOver", bundle: storyboardsBundle)
Expand Down Expand Up @@ -74,7 +75,12 @@ open class PopOverViewController: UITableViewController, UIAdaptivePresentationC
@objc open func set(cellHeight: CGFloat) {
self.cellHeight = cellHeight
}

@objc open func set(titleLabelTextAlignment:NSTextAlignment){
self.titleLabelTextAlignment = titleLabelTextAlignment
}
@objc open func set(detailLabelTextAlignment:NSTextAlignment){
self.detailLabelTextAlignment = detailLabelTextAlignment
}
@objc open func set(selectRow: Int) {
self.selectRow = selectRow
}
Expand All @@ -94,7 +100,6 @@ open class PopOverViewController: UITableViewController, UIAdaptivePresentationC
@objc open func set(showsVerticalScrollIndicator: Bool) {
self.storedShowsVerticalScrollIndicator = showsVerticalScrollIndicator
}

static func getStoryboardsBundle() -> Bundle {
let podBundle = Bundle(for: PopOverViewController.self)
let bundleURL = podBundle.url(forResource: "PopOverMenuStoryboards", withExtension: "bundle")
Expand Down
19 changes: 9 additions & 10 deletions Storyboards/PopOver.storyboard
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Pop Over View Controller-->
<scene sceneID="fol-ry-ts1">
<objects>
<tableViewController storyboardIdentifier="PopOverViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="tDm-Ay-H1K" customClass="PopOverViewController" customModule="PopOverMenu" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="dGh-as-U5K">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="dGh-as-U5K">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<inset key="separatorInset" minX="15" minY="0.0" maxX="15" maxY="0.0"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="gray" indentationWidth="10" reuseIdentifier="SubTitleCell" textLabel="8IC-9V-AUH" detailTextLabel="viF-a9-CyN" style="IBUITableViewCellStyleSubtitle" id="el8-Tp-Jio">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="gray" indentationWidth="10" reuseIdentifier="SubTitleCell" textLabel="8IC-9V-AUH" detailTextLabel="viF-a9-CyN" style="IBUITableViewCellStyleSubtitle" id="el8-Tp-Jio" customClass="PopOverMenuTableViewCell" customModule="PopOverMenu">
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="el8-Tp-Jio" id="IRZ-qd-h3d">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="8IC-9V-AUH">
<rect key="frame" x="15" y="7" width="30" height="18"/>
<rect key="frame" x="16" y="7" width="30" height="18"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="viF-a9-CyN">
<rect key="frame" x="15" y="25" width="37.5" height="12"/>
<rect key="frame" x="16" y="25" width="37.5" height="12"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="10"/>
<color key="textColor" red="0.45882352939999999" green="0.45882352939999999" blue="0.45882352939999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand All @@ -50,7 +49,7 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="GJ4-8P-iJc">
<rect key="frame" x="15" y="0.0" width="345" height="44"/>
<rect key="frame" x="16" y="0.0" width="343" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="textColor"/>
Expand Down