diff --git a/Images/constraint.png b/Images/constraint.png new file mode 100644 index 0000000..8d95cf8 Binary files /dev/null and b/Images/constraint.png differ diff --git a/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample.xcodeproj/project.pbxproj b/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample.xcodeproj/project.pbxproj index 5b648b5..e9a87f5 100644 --- a/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample.xcodeproj/project.pbxproj +++ b/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 50F1DDE31FCC267900600110 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F1DDE21FCC267900600110 /* Extensions.swift */; }; 9902DE341FBB2659009E0D48 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9902DE331FBB2659009E0D48 /* AppDelegate.swift */; }; 9902DE361FBB2659009E0D48 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9902DE351FBB2659009E0D48 /* ViewController.swift */; }; 9902DE391FBB2659009E0D48 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9902DE371FBB2659009E0D48 /* Main.storyboard */; }; @@ -39,6 +40,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 50F1DDE21FCC267900600110 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; 9902DE301FBB2659009E0D48 /* KeyboardLayoutGuideExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KeyboardLayoutGuideExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9902DE331FBB2659009E0D48 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 9902DE351FBB2659009E0D48 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -82,6 +84,7 @@ children = ( 9902DE331FBB2659009E0D48 /* AppDelegate.swift */, 9902DE351FBB2659009E0D48 /* ViewController.swift */, + 50F1DDE21FCC267900600110 /* Extensions.swift */, 9902DE371FBB2659009E0D48 /* Main.storyboard */, 9902DE3A1FBB2659009E0D48 /* Assets.xcassets */, 9902DE3C1FBB2659009E0D48 /* LaunchScreen.storyboard */, @@ -197,6 +200,7 @@ files = ( 9902DE361FBB2659009E0D48 /* ViewController.swift in Sources */, 9902DE341FBB2659009E0D48 /* AppDelegate.swift in Sources */, + 50F1DDE31FCC267900600110 /* Extensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample/Base.lproj/Main.storyboard b/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample/Base.lproj/Main.storyboard index bfe1a0c..9b0be46 100644 --- a/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample/Base.lproj/Main.storyboard +++ b/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample/Base.lproj/Main.storyboard @@ -18,21 +18,32 @@ - + + + + - + + + + - + diff --git a/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample/Extensions.swift b/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample/Extensions.swift new file mode 100644 index 0000000..fb66a2c --- /dev/null +++ b/KeyboardLayoutGuideExample/KeyboardLayoutGuideExample/Extensions.swift @@ -0,0 +1,53 @@ +// +// Extensions.swift +// KeyboardLayoutGuideExample +// +// Created by Max Konovalov on 27/11/2017. +// Copyright © 2017 freshos. All rights reserved. +// + +import UIKit + +extension ViewController: UITextFieldDelegate { + + func textFieldShouldReturn(_ textField: UITextField) -> Bool { + textField.resignFirstResponder() + return false + } + + @IBAction func buttonTapped(_ sender: Any) { + guard let textField = view.subviews.first as? UITextField else { + return + } + if textField.isFirstResponder { + textField.resignFirstResponder() + } else { + textField.becomeFirstResponder() + } + } + +} + +class InvertedButton: UIButton { + + override var isHighlighted: Bool { + didSet { + updateBackgroundColor() + } + } + + override func awakeFromNib() { + super.awakeFromNib() + updateBackgroundColor() + } + + override func tintColorDidChange() { + super.tintColorDidChange() + updateBackgroundColor() + } + + private func updateBackgroundColor() { + backgroundColor = isHighlighted ? tintColor.withAlphaComponent(0.5) : tintColor + } + +} diff --git a/README.md b/README.md index bef0a65..66f4dcb 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ override func viewDidLoad() { } ``` +If you add your view in Interface Builder, don't forget to enable the "**Remove at build time**" checkbox for the bottom constraint: + + + ## Installation ### CocoaPods