diff --git a/PopOverMenuTableViewCell.swift b/PopOverMenuTableViewCell.swift new file mode 100644 index 0000000..ac10630 --- /dev/null +++ b/PopOverMenuTableViewCell.swift @@ -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) + } +} diff --git a/Sources/PopOverViewController+TableView.swift b/Sources/PopOverViewController+TableView.swift index 88e353d..60fb405 100644 --- a/Sources/PopOverViewController+TableView.swift +++ b/Sources/PopOverViewController+TableView.swift @@ -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 } diff --git a/Sources/PopOverViewController.swift b/Sources/PopOverViewController.swift index 3b7f904..66f9332 100644 --- a/Sources/PopOverViewController.swift +++ b/Sources/PopOverViewController.swift @@ -3,12 +3,12 @@ // 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) @@ -16,7 +16,8 @@ open class PopOverViewController: UITableViewController, UIAdaptivePresentationC 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) @@ -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 } @@ -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") diff --git a/Storyboards/PopOver.storyboard b/Storyboards/PopOver.storyboard index b861403..780ca76 100644 --- a/Storyboards/PopOver.storyboard +++ b/Storyboards/PopOver.storyboard @@ -1,10 +1,9 @@ - - - - + + - + + @@ -12,13 +11,13 @@ - + - + @@ -26,14 +25,14 @@