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

Additional LicensesViewControllerConfiguration-struct #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
69 changes: 59 additions & 10 deletions LicensesViewController/LicensesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ open class LicensesViewController: UIViewController {
fileprivate var didSetupConstraints = false

fileprivate let reuseIdentifier = "LicenseCell"

public var configuration: LicensesViewControllerConfiguration? {
didSet {
if let tableViewBackgroundColor = configuration?.tableViewBackgroundColor {
tableView.backgroundColor = tableViewBackgroundColor
}
if let tableViewSeparatorColor = configuration?.tableViewSeparatorColor {
tableView.separatorColor = tableViewSeparatorColor
}
tableView.reloadData()
}
}

open override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -89,8 +101,26 @@ open class LicensesViewController: UIViewController {
dataSource = LicensesDataSource(reuseIdentifier: reuseIdentifier,
items: licenseItems,
configureCell: { (cell: LicenseCell, item: LicenseItem) in

if let cellBackgroundColor = self.configuration?.cellBackgroundColor {
cell.contentView.backgroundColor = cellBackgroundColor
}

cell.titleLabel.text = item.title
if let cellTitleFont = self.configuration?.cellTitleFont {
cell.titleLabel.font = cellTitleFont
}
if let cellTitleFontColor = self.configuration?.cellTitleFontColor {
cell.titleLabel.textColor = cellTitleFontColor
}

cell.bodyLabel.text = item.body
if let cellBodyFont = self.configuration?.cellBodyFont {
cell.bodyLabel.font = cellBodyFont
}
if let cellBodyFontColor = self.configuration?.cellBodyFontColor {
cell.bodyLabel.textColor = cellBodyFontColor
}
})
tableView.dataSource = dataSource
}
Expand Down Expand Up @@ -124,22 +154,14 @@ class LicenseCell: UITableViewCell {

selectionStyle = .none

if #available(iOS 13.0, tvOS 13.0, *) {
titleLabel.textColor = UIColor.label
} else {
titleLabel.textColor = UIColor.black
}
titleLabel.textColor = UIColor.black
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.headline)
titleLabel.lineBreakMode = .byTruncatingTail
titleLabel.numberOfLines = 1
contentView.addSubview(titleLabel)

if #available(iOS 13.0, tvOS 13.0, *) {
bodyLabel.textColor = UIColor.secondaryLabel
} else {
bodyLabel.textColor = UIColor.darkGray
}
bodyLabel.textColor = UIColor.darkGray
bodyLabel.translatesAutoresizingMaskIntoConstraints = false
bodyLabel.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.footnote)
bodyLabel.lineBreakMode = .byWordWrapping
Expand Down Expand Up @@ -256,3 +278,30 @@ struct LicenseItem {
var title: String?
var body: String?
}

/**
Information struct, to configure the LicensesViewController to the project needs.
*/
public struct LicensesViewControllerConfiguration {
/// The background color for the UITableView.
public var tableViewBackgroundColor: UIColor?
/// The separator color for the UITableView.
public var tableViewSeparatorColor: UIColor?

/// The background color for the UITableViewCell.
public var cellBackgroundColor: UIColor?

/// The font color for the title label.
public var cellTitleFontColor: UIColor?
/// The font for the title label.
public var cellTitleFont: UIFont?

/// The font color for the body label.
public var cellBodyFontColor: UIColor?
/// The font for the body label.
public var cellBodyFont: UIFont?

public init() {
// Empty
}
}