From 411c966281e9416382f148c9c1c73483b5f25617 Mon Sep 17 00:00:00 2001 From: Chanchal Raj Date: Fri, 4 Dec 2020 11:34:50 +0400 Subject: [PATCH 1/3] Title and detail title text alignment attribute made settable. --- PopOverMenuTableViewCell.swift | 27 +++++++++++++++++++ Sources/PopOverViewController+TableView.swift | 3 ++- Sources/PopOverViewController.swift | 10 +++++-- Storyboards/PopOver.storyboard | 17 ++++++------ 4 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 PopOverMenuTableViewCell.swift 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..4a525dc 100644 --- a/Sources/PopOverViewController+TableView.swift +++ b/Sources/PopOverViewController+TableView.swift @@ -52,7 +52,8 @@ 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 return cell } diff --git a/Sources/PopOverViewController.swift b/Sources/PopOverViewController.swift index 3b7f904..54ed00f 100644 --- a/Sources/PopOverViewController.swift +++ b/Sources/PopOverViewController.swift @@ -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 } diff --git a/Storyboards/PopOver.storyboard b/Storyboards/PopOver.storyboard index b861403..ba4aaa6 100644 --- a/Storyboards/PopOver.storyboard +++ b/Storyboards/PopOver.storyboard @@ -1,10 +1,9 @@ - - - - + + - + + @@ -18,7 +17,7 @@ - + @@ -26,14 +25,14 @@