Skip to content
Merged
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 Images/constraint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -39,6 +40,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
50F1DDE21FCC267900600110 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
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 = "<group>"; };
9902DE351FBB2659009E0D48 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -82,6 +84,7 @@
children = (
9902DE331FBB2659009E0D48 /* AppDelegate.swift */,
9902DE351FBB2659009E0D48 /* ViewController.swift */,
50F1DDE21FCC267900600110 /* Extensions.swift */,
9902DE371FBB2659009E0D48 /* Main.storyboard */,
9902DE3A1FBB2659009E0D48 /* Assets.xcassets */,
9902DE3C1FBB2659009E0D48 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -197,6 +200,7 @@
files = (
9902DE361FBB2659009E0D48 /* ViewController.swift in Sources */,
9902DE341FBB2659009E0D48 /* AppDelegate.swift in Sources */,
50F1DDE31FCC267900600110 /* Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,32 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Try me!" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="fx8-LQ-Nzs">
<rect key="frame" x="16" y="175" width="343" height="30"/>
<rect key="frame" x="16" y="175" width="343" height="40"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="DGk-vX-h2V"/>
</constraints>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<textInputTraits key="textInputTraits"/>
<connections>
<outlet property="delegate" destination="BYZ-38-t0r" id="kot-bW-Hrl"/>
</connections>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HGh-qK-wBn">
<rect key="frame" x="0.0" y="567" width="375" height="100"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HGh-qK-wBn" customClass="InvertedButton" customModule="KeyboardLayoutGuideExample" customModuleProvider="target">
<rect key="frame" x="0.0" y="617" width="375" height="50"/>
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" constant="100" id="Q6h-Ut-Aft"/>
<constraint firstAttribute="height" constant="50" id="Q6h-Ut-Aft"/>
</constraints>
<state key="normal" title="Button"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="18"/>
<state key="normal" title="Tap me!"/>
<connections>
<action selector="buttonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="mKh-YQ-EPx"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<gestureRecognizers/>
<constraints>
<constraint firstItem="HGh-qK-wBn" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="7n9-b9-wjj"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="fx8-LQ-Nzs" secondAttribute="trailing" constant="16" id="Bfi-Vl-BMd"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}

}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<img src="Images/constraint.png" width=258>

## Installation

### CocoaPods
Expand Down