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

Cell customization #144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
12 changes: 12 additions & 0 deletions CountryPickerView/CountryPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ extension CountryPickerViewController {
if let color = dataSource.cellLabelColor {
cell.textLabel?.textColor = color
}
if let color = dataSource.cellBackgroundColor {
cell.backgroundColor = color
}
cell.selectionStyle = dataSource.cellSelectionStyle
cell.accessoryType = country == countryPickerView.selectedCountry &&
dataSource.showCheckmarkInList ? .checkmark : .none
cell.separatorInset = .zero
Expand Down Expand Up @@ -313,6 +317,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)
}
Expand All @@ -321,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)
}
Expand Down
14 changes: 14 additions & 0 deletions CountryPickerView/Delegate+DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ 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

/// 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?

Expand Down Expand Up @@ -115,6 +121,10 @@ public extension CountryPickerViewDataSource {
return nil
}

func cellBackgroundColor(in countryPickerView: CountryPickerView) -> UIColor? {
return nil
}

func cellImageViewCornerRadius(in countryPickerView: CountryPickerView) -> CGFloat {
return 2
}
Expand All @@ -123,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
}
Expand Down