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

Feature/fix colours #152

Open
wants to merge 6 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
Binary file added .DS_Store
Binary file not shown.
16 changes: 8 additions & 8 deletions CountryPickerView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
/* Begin PBXBuildFile section */
004CA2F01F7056E700B690B8 /* CountryPickerView.h in Headers */ = {isa = PBXBuildFile; fileRef = 004CA2EE1F7056E700B690B8 /* CountryPickerView.h */; settings = {ATTRIBUTES = (Public, ); }; };
004CA3221F70609900B690B8 /* CountryPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 004CA3211F70609900B690B8 /* CountryPickerView.swift */; };
004CA32F1F706DF500B690B8 /* CountryPickerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 004CA32E1F706DF500B690B8 /* CountryPickerView.xib */; };
004CA3311F70782400B690B8 /* CountryPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 004CA3301F70782400B690B8 /* CountryPickerViewController.swift */; };
004CA3331F70787200B690B8 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 004CA3321F70787200B690B8 /* Extensions.swift */; };
00B095FC1F75AD6200860F82 /* NibView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B095FB1F75AD6200860F82 /* NibView.swift */; };
12BA28E4288AB80600E816C1 /* CountryPickerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 12BA28E3288AB80600E816C1 /* CountryPickerView.xib */; };
12BA28E6288AB83000E816C1 /* CountryPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA28E5288AB83000E816C1 /* CountryPickerViewController.swift */; };
50468942203753BF00009BA1 /* Delegate+DataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50468941203753BF00009BA1 /* Delegate+DataSource.swift */; };
743599E0270895CF003EBF60 /* Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 743599DF270895CE003EBF60 /* Bundle.swift */; };
/* End PBXBuildFile section */
Expand All @@ -22,10 +22,10 @@
004CA2EE1F7056E700B690B8 /* CountryPickerView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CountryPickerView.h; sourceTree = "<group>"; };
004CA2EF1F7056E700B690B8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
004CA3211F70609900B690B8 /* CountryPickerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountryPickerView.swift; sourceTree = "<group>"; };
004CA32E1F706DF500B690B8 /* CountryPickerView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CountryPickerView.xib; sourceTree = "<group>"; };
004CA3301F70782400B690B8 /* CountryPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountryPickerViewController.swift; sourceTree = "<group>"; };
004CA3321F70787200B690B8 /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
00B095FB1F75AD6200860F82 /* NibView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NibView.swift; sourceTree = "<group>"; };
12BA28E3288AB80600E816C1 /* CountryPickerView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CountryPickerView.xib; sourceTree = "<group>"; };
12BA28E5288AB83000E816C1 /* CountryPickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CountryPickerViewController.swift; sourceTree = "<group>"; };
50468941203753BF00009BA1 /* Delegate+DataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Delegate+DataSource.swift"; sourceTree = "<group>"; };
743599DF270895CE003EBF60 /* Bundle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Bundle.swift; sourceTree = "<group>"; };
74359C1E2708A5D1003EBF60 /* TG.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = TG.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -321,10 +321,11 @@
004CA2EE1F7056E700B690B8 /* CountryPickerView.h */,
004CA2EF1F7056E700B690B8 /* Info.plist */,
004CA3211F70609900B690B8 /* CountryPickerView.swift */,
004CA3301F70782400B690B8 /* CountryPickerViewController.swift */,
004CA3321F70787200B690B8 /* Extensions.swift */,
00B095FB1F75AD6200860F82 /* NibView.swift */,
50468941203753BF00009BA1 /* Delegate+DataSource.swift */,
12BA28E3288AB80600E816C1 /* CountryPickerView.xib */,
12BA28E5288AB83000E816C1 /* CountryPickerViewController.swift */,
);
path = CountryPickerView;
sourceTree = "<group>";
Expand All @@ -334,7 +335,6 @@
children = (
74359D1B2708A5D1003EBF60 /* Data */,
74359C1D2708A5D1003EBF60 /* Images */,
004CA32E1F706DF500B690B8 /* CountryPickerView.xib */,
);
path = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -679,7 +679,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
004CA32F1F706DF500B690B8 /* CountryPickerView.xib in Resources */,
12BA28E4288AB80600E816C1 /* CountryPickerView.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -693,9 +693,9 @@
50468942203753BF00009BA1 /* Delegate+DataSource.swift in Sources */,
743599E0270895CF003EBF60 /* Bundle.swift in Sources */,
00B095FC1F75AD6200860F82 /* NibView.swift in Sources */,
004CA3311F70782400B690B8 /* CountryPickerViewController.swift in Sources */,
004CA3331F70787200B690B8 /* Extensions.swift in Sources */,
004CA3221F70609900B690B8 /* CountryPickerView.swift in Sources */,
12BA28E6288AB83000E816C1 /* CountryPickerViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 1 addition & 0 deletions CountryPickerView/CountryPickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,4 @@ extension CountryPickerView {
return countries.first(where: { $0.code == code })
}
}

Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CountryPickerView" customModule="CountryPickerView" customModuleProvider="target">
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="CountryPickerView" customModule="CountryPickerView_CountryPickerView" customModuleProvider="target">
<connections>
<outlet property="countryDetailsLabel" destination="4Mf-hk-O6C" id="1Dv-CS-6Cf"/>
<outlet property="flagImageView" destination="0ui-wz-fhH" id="aWg-vy-G4b"/>
Expand All @@ -25,10 +23,10 @@
<rect key="frame" x="0.0" y="0.0" width="346" height="94"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="750" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="0ui-wz-fhH">
<rect key="frame" x="0.0" y="0.5" width="256" height="94"/>
<rect key="frame" x="16" y="20" width="216" height="54"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="1000" text="(NG) +234" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4Mf-hk-O6C">
<rect key="frame" x="264" y="-0.5" width="82" height="94.5"/>
<rect key="frame" x="240" y="0.0" width="82" height="94"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand All @@ -37,13 +35,14 @@
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<gestureRecognizers/>
<constraints>
<constraint firstAttribute="trailing" secondItem="4Mf-hk-O6C" secondAttribute="trailing" id="GOz-D9-UZP"/>
<constraint firstItem="0ui-wz-fhH" firstAttribute="top" secondItem="rOy-96-GKY" secondAttribute="top" constant="20" id="ACW-kC-5xt"/>
<constraint firstItem="4Mf-hk-O6C" firstAttribute="centerY" secondItem="rOy-96-GKY" secondAttribute="centerY" id="K0F-Oh-iPl"/>
<constraint firstItem="0ui-wz-fhH" firstAttribute="leading" secondItem="rOy-96-GKY" secondAttribute="leading" id="R2F-Rd-8PH"/>
<constraint firstItem="0ui-wz-fhH" firstAttribute="height" secondItem="rOy-96-GKY" secondAttribute="height" id="SEs-55-b9c"/>
<constraint firstItem="0ui-wz-fhH" firstAttribute="leading" secondItem="rOy-96-GKY" secondAttribute="leading" constant="16" id="Tw8-Wb-m9N"/>
<constraint firstAttribute="trailing" secondItem="4Mf-hk-O6C" secondAttribute="trailing" constant="24" id="bOj-ik-aKN"/>
<constraint firstItem="0ui-wz-fhH" firstAttribute="centerY" secondItem="rOy-96-GKY" secondAttribute="centerY" id="bm9-la-i16"/>
<constraint firstItem="4Mf-hk-O6C" firstAttribute="leading" secondItem="0ui-wz-fhH" secondAttribute="trailing" constant="8" id="f2R-wJ-cfm"/>
<constraint firstItem="4Mf-hk-O6C" firstAttribute="height" secondItem="rOy-96-GKY" secondAttribute="height" id="grh-0A-Y04"/>
<constraint firstAttribute="bottom" secondItem="0ui-wz-fhH" secondAttribute="bottom" constant="20" id="itx-8Y-HR3"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
Expand Down
86 changes: 80 additions & 6 deletions CountryPickerView/CountryPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,42 @@ public class CountryPickerViewController: UITableViewController {
}
}

public override var preferredStatusBarStyle: UIStatusBarStyle {
.default
}

fileprivate var dataSource: CountryPickerViewDataSourceInternal!

override public func viewDidLoad() {
super.viewDidLoad()

// navigationController?.setNavigationBarHidden(false, animated: false)
// navigationController?.navigationBar.backItem?.title = ""
// navigationController?.navigationBar.tintColor = .gray

prepareTableItems()
prepareNavItem()
prepareSearchBar()
}


public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .coralRed
navigationController?.navigationBar.standardAppearance = appearance;
navigationController?.navigationBar.scrollEdgeAppearance = navigationController?.navigationBar.standardAppearance
}
navigationController?.setNavigationBarHidden(false, animated: false)
navigationController?.navigationBar.backItem?.title = ""
navigationController?.navigationBar.tintColor = .white
}

public override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
}

// UI Setup
Expand Down Expand Up @@ -73,8 +99,7 @@ extension CountryPickerViewController {
}

func prepareNavItem() {
navigationItem.title = dataSource.navigationTitle

// navigationItem.title = dataSource.navigationTitle
// Add a close button if this is the root view controller
if navigationController?.viewControllers.count == 1 {
let closeButton = dataSource.closeButtonNavigationItem
Expand All @@ -94,9 +119,14 @@ extension CountryPickerViewController {
searchController?.dimsBackgroundDuringPresentation = false
searchController?.hidesNavigationBarDuringPresentation = searchBarPosition == .tableViewHeader
searchController?.definesPresentationContext = true
if #available(iOS 13.0, *) {

// searchController?.searchBar.backgroundColor = .white
searchController?.searchBar.searchTextField.backgroundColor = .white
searchController?.searchBar.tintColor = .gray
}
searchController?.searchBar.delegate = self
searchController?.delegate = self

switch searchBarPosition {
case .tableViewHeader: tableView.tableHeaderView = searchController?.searchBar
case .navigationBar: navigationItem.titleView = searchController?.searchBar
Expand Down Expand Up @@ -239,8 +269,8 @@ extension CountryPickerViewController: UISearchResultsUpdating {
extension CountryPickerViewController: UISearchBarDelegate {
public func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
// Hide the back/left navigationItem button
navigationItem.leftBarButtonItem = nil
navigationItem.hidesBackButton = true
// navigationItem.leftBarButtonItem = nil
navigationItem.hidesBackButton = false
}

public func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
Expand All @@ -254,10 +284,12 @@ extension CountryPickerViewController: UISearchBarDelegate {
// Fixes an issue where the search bar goes off screen sometimes.
extension CountryPickerViewController: UISearchControllerDelegate {
public func willPresentSearchController(_ searchController: UISearchController) {
searchController.searchBar.showsCancelButton = false
self.navigationController?.navigationBar.isTranslucent = true
}

public func willDismissSearchController(_ searchController: UISearchController) {
searchController.searchBar.showsCancelButton = false
self.navigationController?.navigationBar.isTranslucent = false
}
}
Expand Down Expand Up @@ -356,3 +388,45 @@ class CountryPickerViewDataSourceInternal: CountryPickerViewDataSource {
return view.dataSource?.excludedCountries(in: view) ?? excludedCountries(in: view)
}
}

extension UIColor {
convenience init(hexString: String) {
let scanner = Scanner(string: hexString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines))
if (hexString.hasPrefix("#")) {
scanner.scanLocation = 1
}

var color:UInt32 = 0
scanner.scanHexInt32(&color)

let mask = 0x000000FF
let r = Int(color >> 16) & mask
let g = Int(color >> 8) & mask
let b = Int(color) & mask

let red = CGFloat(r) / 255.0
let green = CGFloat(g) / 255.0
let blue = CGFloat(b) / 255.0

self.init(red:red, green:green, blue:blue, alpha:1)
}

func toHexString() -> String {
var r:CGFloat = 0
var g:CGFloat = 0
var b:CGFloat = 0
var a:CGFloat = 0

getRed(&r, green: &g, blue: &b, alpha: &a)

let rgb:Int = (Int)(r*255)<<16 | (Int)(g*255)<<8 | (Int)(b*255)<<0

return String(format:"#%06x", rgb)
}
}

extension UIColor {
static var coralRed: UIColor {
return UIColor(hexString: "#fd6368")
}
}