InKwon James Kim
5 years ago
9 changed files with 168 additions and 22 deletions
-
4GME Remit.xcodeproj/project.pbxproj
-
2GME Remit/AppDelegate.swift
-
98GME Remit/Extensions/UISearchBar+Ext.swift
-
4GME Remit/Modules/RemittanceModules/DomesticModules/RecentHistories/Application Logic/Model/RecentRecipientModel.swift
-
45GME Remit/Modules/RemittanceModules/DomesticModules/RecentHistories/User Interface/View/RecentHistories.storyboard
-
16GME Remit/Modules/RemittanceModules/DomesticModules/RecentHistories/User Interface/View/RecentHistoriesViewController.swift
-
8GME Remit/Modules/RemittanceModules/DomesticModules/RecentHistories/User Interface/View/ViewModel/RecentHistoriesViewModel.swift
-
6GME Remit/MultiLanguages/ko.lproj/Localizable.strings
-
7GME Remit/Utilities/TablePresenter/User Interface/View/TablePresenterViewController.swift
@ -0,0 +1,98 @@ |
|||
// |
|||
// UISearchBar+Ext.swift |
|||
// GME Remit |
|||
// |
|||
// Created by InKwon James Kim on 25/09/2019. |
|||
// Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved. |
|||
// |
|||
|
|||
import UIKit |
|||
|
|||
extension UISearchBar { |
|||
func getTextField() -> UITextField? { return value(forKey: "searchField") as? UITextField } |
|||
|
|||
func set(textColor: UIColor) { if let textField = getTextField() { textField.textColor = textColor } } |
|||
|
|||
func setPlaceholder(textColor: UIColor) { getTextField()?.setPlaceholder(textColor: textColor) } |
|||
|
|||
func setClearButton(color: UIColor) { getTextField()?.setClearButton(color: color) } |
|||
|
|||
func setTextField(color: UIColor) { |
|||
guard let textField = getTextField() else { return } |
|||
switch searchBarStyle { |
|||
case .minimal: |
|||
textField.layer.backgroundColor = color.cgColor |
|||
textField.layer.cornerRadius = 6 |
|||
case .prominent, .default: textField.backgroundColor = color |
|||
@unknown default: break |
|||
} |
|||
} |
|||
|
|||
func setSearchImage(color: UIColor) { |
|||
guard let imageView = getTextField()?.leftView as? UIImageView else { return } |
|||
imageView.tintColor = color |
|||
imageView.image = imageView.image?.withRenderingMode(.alwaysTemplate) |
|||
} |
|||
} |
|||
|
|||
private extension UITextField { |
|||
|
|||
private class Label: UILabel { |
|||
private var _textColor = UIColor.lightGray |
|||
override var textColor: UIColor! { |
|||
set { super.textColor = _textColor } |
|||
get { return _textColor } |
|||
} |
|||
|
|||
init(label: UILabel, textColor: UIColor = .lightGray) { |
|||
_textColor = textColor |
|||
super.init(frame: label.frame) |
|||
self.text = label.text |
|||
self.font = label.font |
|||
} |
|||
|
|||
required init?(coder: NSCoder) { super.init(coder: coder) } |
|||
} |
|||
|
|||
|
|||
private class ClearButtonImage { |
|||
static private var _image: UIImage? |
|||
static private var semaphore = DispatchSemaphore(value: 1) |
|||
static func getImage(closure: @escaping (UIImage?)->()) { |
|||
DispatchQueue.global(qos: .userInteractive).async { |
|||
semaphore.wait() |
|||
DispatchQueue.main.async { |
|||
if let image = _image { closure(image); semaphore.signal(); return } |
|||
guard let window = UIApplication.shared.windows.first else { semaphore.signal(); return } |
|||
let searchBar = UISearchBar(frame: CGRect(x: 0, y: -200, width: UIScreen.main.bounds.width, height: 44)) |
|||
window.rootViewController?.view.addSubview(searchBar) |
|||
searchBar.text = "txt" |
|||
searchBar.layoutIfNeeded() |
|||
_image = searchBar.getTextField()?.getClearButton()?.image(for: .normal) |
|||
closure(_image) |
|||
searchBar.removeFromSuperview() |
|||
semaphore.signal() |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
func setClearButton(color: UIColor) { |
|||
ClearButtonImage.getImage { [weak self] image in |
|||
guard let image = image, |
|||
let button = self?.getClearButton() else { return } |
|||
button.imageView?.tintColor = color |
|||
button.setImage(image.withRenderingMode(.alwaysTemplate), for: .normal) |
|||
} |
|||
} |
|||
|
|||
var placeholderLabel: UILabel? { return value(forKey: "placeholderLabel") as? UILabel } |
|||
|
|||
func setPlaceholder(textColor: UIColor) { |
|||
guard let placeholderLabel = placeholderLabel else { return } |
|||
let label = Label(label: placeholderLabel, textColor: textColor) |
|||
setValue(label, forKey: "placeholderLabel") |
|||
} |
|||
|
|||
func getClearButton() -> UIButton? { return value(forKey: "clearButton") as? UIButton } |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue