diff --git a/RealmVideo.xcodeproj/project.pbxproj b/RealmVideo.xcodeproj/project.pbxproj index 63eeb1c..897fad8 100644 --- a/RealmVideo.xcodeproj/project.pbxproj +++ b/RealmVideo.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ AE01EFB21CDD478000F200D3 /* RealmParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE01EFB11CDD478000F200D3 /* RealmParser.swift */; }; AE01EFB41CDD479300F200D3 /* Video.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE01EFB31CDD479300F200D3 /* Video.swift */; }; AE4854881CE1CB95006ADC0E /* SlidePosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE4854871CE1CB95006ADC0E /* SlidePosition.swift */; }; + AE48548E1CE1CFF8006ADC0E /* SearchTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE48548D1CE1CFF8006ADC0E /* SearchTextField.swift */; }; AE5248601CDBB05B003B7454 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE52485F1CDBB05B003B7454 /* AppDelegate.swift */; }; AE5248621CDBB05B003B7454 /* RealmVideoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE5248611CDBB05B003B7454 /* RealmVideoViewController.swift */; }; AE5248651CDBB05B003B7454 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AE5248631CDBB05B003B7454 /* Main.storyboard */; }; @@ -26,6 +27,7 @@ AE01EFB11CDD478000F200D3 /* RealmParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RealmParser.swift; sourceTree = ""; }; AE01EFB31CDD479300F200D3 /* Video.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Video.swift; sourceTree = ""; }; AE4854871CE1CB95006ADC0E /* SlidePosition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlidePosition.swift; sourceTree = ""; }; + AE48548D1CE1CFF8006ADC0E /* SearchTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchTextField.swift; sourceTree = ""; }; AE52485C1CDBB05B003B7454 /* RealmVideo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RealmVideo.app; sourceTree = BUILT_PRODUCTS_DIR; }; AE52485F1CDBB05B003B7454 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; AE5248611CDBB05B003B7454 /* RealmVideoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RealmVideoViewController.swift; sourceTree = ""; }; @@ -92,6 +94,14 @@ name = Utils; sourceTree = ""; }; + AE48548F1CE1CFFE006ADC0E /* Views */ = { + isa = PBXGroup; + children = ( + AE48548D1CE1CFF8006ADC0E /* SearchTextField.swift */, + ); + name = Views; + sourceTree = ""; + }; AE5248531CDBB05B003B7454 = { isa = PBXGroup; children = ( @@ -115,6 +125,7 @@ children = ( AE52485F1CDBB05B003B7454 /* AppDelegate.swift */, AE4854891CE1CBA8006ADC0E /* View Controllers */, + AE48548F1CE1CFFE006ADC0E /* Views */, AE48548A1CE1CBB1006ADC0E /* Parsing */, AE48548C1CE1CBCA006ADC0E /* Utils */, AE48548B1CE1CBC5006ADC0E /* Model */, @@ -264,6 +275,7 @@ AE5248601CDBB05B003B7454 /* AppDelegate.swift in Sources */, AE4854881CE1CB95006ADC0E /* SlidePosition.swift in Sources */, AE01EFB21CDD478000F200D3 /* RealmParser.swift in Sources */, + AE48548E1CE1CFF8006ADC0E /* SearchTextField.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/RealmVideo/Base.lproj/Main.storyboard b/RealmVideo/Base.lproj/Main.storyboard index 45ecc13..71918ff 100644 --- a/RealmVideo/Base.lproj/Main.storyboard +++ b/RealmVideo/Base.lproj/Main.storyboard @@ -198,7 +198,7 @@ - + diff --git a/RealmVideo/SearchTextField.swift b/RealmVideo/SearchTextField.swift new file mode 100644 index 0000000..e92a1d1 --- /dev/null +++ b/RealmVideo/SearchTextField.swift @@ -0,0 +1,46 @@ +// +// SearchTextField.swift +// RealmVideo +// +// Created by Patrick Balestra on 5/10/16. +// Copyright © 2016 Patrick Balestra. All rights reserved. +// + +import UIKit + +@IBDesignable class SearchTextField: UITextField { + + override init(frame: CGRect) { + super.init(frame: frame) + setUp() + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + setUp() + } + + func setUp() { + layer.borderColor = UIColor.whiteColor().CGColor + layer.borderWidth = 1.0 + layer.cornerRadius = 5.0 + tintColor = UIColor.whiteColor() + + let placeholder = NSAttributedString(string: "realm.io/...", attributes: [NSForegroundColorAttributeName : UIColor(white: 1.0, alpha: 0.5)]) + attributedPlaceholder = placeholder + + let clearButton = UIButton(type: .Custom) + clearButton.setImage(UIImage(named: "clear-icon"), forState: .Normal) + clearButton.frame = CGRect(x: 0, y: 0, width: 25.0, height: 15.0) + clearButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10) + rightView = clearButton + rightViewMode = .Always + clearButton.addTarget(self, action: #selector(clearTextField), forControlEvents: .TouchUpInside) + } + + func clearTextField() { + text = "" + } + + +} diff --git a/RealmVideo/WelcomeViewController.swift b/RealmVideo/WelcomeViewController.swift index 1c14117..38ab416 100644 --- a/RealmVideo/WelcomeViewController.swift +++ b/RealmVideo/WelcomeViewController.swift @@ -10,36 +10,21 @@ import UIKit class WelcomeViewController: UIViewController, UITextFieldDelegate { - @IBOutlet weak var textField: UITextField! + @IBOutlet weak var textField: SearchTextField! @IBOutlet weak var startVideo: UIButton! - @IBOutlet var pasteClipboardButton: UIButton! - @IBOutlet var scrollView: UIScrollView! + @IBOutlet weak var pasteClipboardButton: UIButton! + @IBOutlet weak var scrollView: UIScrollView! override func viewDidLoad() { super.viewDidLoad() - textField.layer.borderColor = UIColor.whiteColor().CGColor - textField.layer.borderWidth = 1.0 - textField.layer.cornerRadius = 5.0 textField.delegate = self - textField.tintColor = UIColor.whiteColor() textField.becomeFirstResponder() - let placeholder = NSAttributedString(string: "realm.io/...", attributes: [NSForegroundColorAttributeName : UIColor(white: 1.0, alpha: 0.5)]) - textField.attributedPlaceholder = placeholder - - let clearButton = UIButton(type: .Custom) - clearButton.setImage(UIImage(named: "clear-icon"), forState: .Normal) - clearButton.frame = CGRect(x: 0, y: 0, width: 25.0, height: 15.0) - clearButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 10) - textField.rightView = clearButton - textField.rightViewMode = .Always - clearButton.addTarget(self, action: #selector(clearTextField), forControlEvents: .TouchUpInside) - setValidLink("") - NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(WelcomeViewController.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil) - NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(WelcomeViewController.keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil) + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillShow), name: UIKeyboardWillShowNotification, object: nil) + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(keyboardWillHide), name: UIKeyboardWillHideNotification, object: nil) } func setValidLink(linkString: String) { @@ -76,10 +61,6 @@ class WelcomeViewController: UIViewController, UITextFieldDelegate { } } - func clearTextField() { - textField.text = "" - } - // MARK: - UITextFieldDelegate func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { @@ -89,7 +70,7 @@ class WelcomeViewController: UIViewController, UITextFieldDelegate { // MARK: - UIKeyboard Notifications - @objc private func keyboardWillShow(notification: NSNotification) { + func keyboardWillShow(notification: NSNotification) { guard let keyboardInfo = notification.userInfo, let keyboardSize = (keyboardInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() else { return } @@ -100,7 +81,7 @@ class WelcomeViewController: UIViewController, UITextFieldDelegate { scrollView.scrollIndicatorInsets = contentInset } - @objc private func keyboardWillHide(notification: NSNotification) { + func keyboardWillHide(notification: NSNotification) { var contentInset = scrollView.contentInset contentInset.bottom = 0