From 9fc199ed96878809ce6f9f5a84409ac05fade55e Mon Sep 17 00:00:00 2001 From: Alex Kovalov Date: Sat, 10 Jul 2021 21:52:38 +0300 Subject: [PATCH 1/2] Add cell background color customization --- CountryPickerView/CountryPickerViewController.swift | 7 +++++++ CountryPickerView/Delegate+DataSource.swift | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/CountryPickerView/CountryPickerViewController.swift b/CountryPickerView/CountryPickerViewController.swift index 54a21e2..0a48dd2 100644 --- a/CountryPickerView/CountryPickerViewController.swift +++ b/CountryPickerView/CountryPickerViewController.swift @@ -149,6 +149,9 @@ extension CountryPickerViewController { if let color = dataSource.cellLabelColor { cell.textLabel?.textColor = color } + if let color = dataSource.cellBackgroundColor { + cell.backgroundColor = color + } cell.accessoryType = country == countryPickerView.selectedCountry && dataSource.showCheckmarkInList ? .checkmark : .none cell.separatorInset = .zero @@ -313,6 +316,10 @@ class CountryPickerViewDataSourceInternal: CountryPickerViewDataSource { return view.dataSource?.cellLabelColor(in: view) } + var cellBackgroundColor: UIColor? { + return view.dataSource?.cellBackgroundColor(in: view) + } + var cellImageViewSize: CGSize { return view.dataSource?.cellImageViewSize(in: view) ?? cellImageViewSize(in: view) } diff --git a/CountryPickerView/Delegate+DataSource.swift b/CountryPickerView/Delegate+DataSource.swift index 076a9ae..4a7cd74 100644 --- a/CountryPickerView/Delegate+DataSource.swift +++ b/CountryPickerView/Delegate+DataSource.swift @@ -50,6 +50,9 @@ public protocol CountryPickerViewDataSource: class { /// The desired text color for the country names on the list. func cellLabelColor(in countryPickerView: CountryPickerView) -> UIColor? + /// The desired background color for the cell in the list. + func cellBackgroundColor(in countryPickerView: CountryPickerView) -> UIColor? + /// The desired size for the flag images on the list. func cellImageViewSize(in countryPickerView: CountryPickerView) -> CGSize @@ -115,6 +118,10 @@ public extension CountryPickerViewDataSource { return nil } + func cellBackgroundColor(in countryPickerView: CountryPickerView) -> UIColor? { + return nil + } + func cellImageViewCornerRadius(in countryPickerView: CountryPickerView) -> CGFloat { return 2 } From 572cb2ec65f3c7fa75602dbb72eba25db69c8ca4 Mon Sep 17 00:00:00 2001 From: Alex Kovalov Date: Sat, 10 Jul 2021 22:14:58 +0300 Subject: [PATCH 2/2] Add cell selection style customization --- CountryPickerView/CountryPickerViewController.swift | 5 +++++ CountryPickerView/Delegate+DataSource.swift | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/CountryPickerView/CountryPickerViewController.swift b/CountryPickerView/CountryPickerViewController.swift index 0a48dd2..386d270 100644 --- a/CountryPickerView/CountryPickerViewController.swift +++ b/CountryPickerView/CountryPickerViewController.swift @@ -152,6 +152,7 @@ extension CountryPickerViewController { if let color = dataSource.cellBackgroundColor { cell.backgroundColor = color } + cell.selectionStyle = dataSource.cellSelectionStyle cell.accessoryType = country == countryPickerView.selectedCountry && dataSource.showCheckmarkInList ? .checkmark : .none cell.separatorInset = .zero @@ -328,6 +329,10 @@ class CountryPickerViewDataSourceInternal: CountryPickerViewDataSource { return view.dataSource?.cellImageViewCornerRadius(in: view) ?? cellImageViewCornerRadius(in: view) } + var cellSelectionStyle: UITableViewCell.SelectionStyle { + return view.dataSource?.cellSelectionStyle(in: view) ?? .default + } + var navigationTitle: String? { return view.dataSource?.navigationTitle(in: view) } diff --git a/CountryPickerView/Delegate+DataSource.swift b/CountryPickerView/Delegate+DataSource.swift index 4a7cd74..7bb8cc3 100644 --- a/CountryPickerView/Delegate+DataSource.swift +++ b/CountryPickerView/Delegate+DataSource.swift @@ -59,6 +59,9 @@ public protocol CountryPickerViewDataSource: class { /// The desired corner radius for the flag images on the list. Default value is 2 func cellImageViewCornerRadius(in countryPickerView: CountryPickerView) -> CGFloat + /// The desired cell selection style. + func cellSelectionStyle(in countryPickerView: CountryPickerView) -> UITableViewCell.SelectionStyle + /// The navigation item title when the internal view controller is pushed/presented. func navigationTitle(in countryPickerView: CountryPickerView) -> String? @@ -130,6 +133,10 @@ public extension CountryPickerViewDataSource { return CGSize(width: 34, height: 24) } + func cellSelectionStyle(in countryPickerView: CountryPickerView) -> UITableViewCell.SelectionStyle { + return .default + } + func navigationTitle(in countryPickerView: CountryPickerView) -> String? { return nil }