Skip to content

Commit 46f7fea

Browse files
authored
Merge pull request #7 from freshOS/example
Better example
2 parents 5793f88 + 83abb7a commit 46f7fea

File tree

5 files changed

+79
-7
lines changed

5 files changed

+79
-7
lines changed

Images/constraint.png

64.8 KB
Loading

KeyboardLayoutGuideExample/KeyboardLayoutGuideExample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
50F1DDE31FCC267900600110 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50F1DDE21FCC267900600110 /* Extensions.swift */; };
1011
9902DE341FBB2659009E0D48 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9902DE331FBB2659009E0D48 /* AppDelegate.swift */; };
1112
9902DE361FBB2659009E0D48 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9902DE351FBB2659009E0D48 /* ViewController.swift */; };
1213
9902DE391FBB2659009E0D48 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9902DE371FBB2659009E0D48 /* Main.storyboard */; };
@@ -39,6 +40,7 @@
3940
/* End PBXContainerItemProxy section */
4041

4142
/* Begin PBXFileReference section */
43+
50F1DDE21FCC267900600110 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
4244
9902DE301FBB2659009E0D48 /* KeyboardLayoutGuideExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KeyboardLayoutGuideExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
4345
9902DE331FBB2659009E0D48 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
4446
9902DE351FBB2659009E0D48 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@@ -82,6 +84,7 @@
8284
children = (
8385
9902DE331FBB2659009E0D48 /* AppDelegate.swift */,
8486
9902DE351FBB2659009E0D48 /* ViewController.swift */,
87+
50F1DDE21FCC267900600110 /* Extensions.swift */,
8588
9902DE371FBB2659009E0D48 /* Main.storyboard */,
8689
9902DE3A1FBB2659009E0D48 /* Assets.xcassets */,
8790
9902DE3C1FBB2659009E0D48 /* LaunchScreen.storyboard */,
@@ -197,6 +200,7 @@
197200
files = (
198201
9902DE361FBB2659009E0D48 /* ViewController.swift in Sources */,
199202
9902DE341FBB2659009E0D48 /* AppDelegate.swift in Sources */,
203+
50F1DDE31FCC267900600110 /* Extensions.swift in Sources */,
200204
);
201205
runOnlyForDeploymentPostprocessing = 0;
202206
};

KeyboardLayoutGuideExample/KeyboardLayoutGuideExample/Base.lproj/Main.storyboard

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,32 @@
1818
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1919
<subviews>
2020
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Try me!" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="fx8-LQ-Nzs">
21-
<rect key="frame" x="16" y="175" width="343" height="30"/>
21+
<rect key="frame" x="16" y="175" width="343" height="40"/>
22+
<constraints>
23+
<constraint firstAttribute="height" constant="40" id="DGk-vX-h2V"/>
24+
</constraints>
2225
<nil key="textColor"/>
23-
<fontDescription key="fontDescription" type="system" pointSize="14"/>
26+
<fontDescription key="fontDescription" type="system" pointSize="16"/>
2427
<textInputTraits key="textInputTraits"/>
28+
<connections>
29+
<outlet property="delegate" destination="BYZ-38-t0r" id="kot-bW-Hrl"/>
30+
</connections>
2531
</textField>
26-
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HGh-qK-wBn">
27-
<rect key="frame" x="0.0" y="567" width="375" height="100"/>
28-
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
32+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HGh-qK-wBn" customClass="InvertedButton" customModule="KeyboardLayoutGuideExample" customModuleProvider="target">
33+
<rect key="frame" x="0.0" y="617" width="375" height="50"/>
34+
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
2935
<constraints>
30-
<constraint firstAttribute="height" constant="100" id="Q6h-Ut-Aft"/>
36+
<constraint firstAttribute="height" constant="50" id="Q6h-Ut-Aft"/>
3137
</constraints>
32-
<state key="normal" title="Button"/>
38+
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="18"/>
39+
<state key="normal" title="Tap me!"/>
40+
<connections>
41+
<action selector="buttonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="mKh-YQ-EPx"/>
42+
</connections>
3343
</button>
3444
</subviews>
3545
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
46+
<gestureRecognizers/>
3647
<constraints>
3748
<constraint firstItem="HGh-qK-wBn" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="7n9-b9-wjj"/>
3849
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="fx8-LQ-Nzs" secondAttribute="trailing" constant="16" id="Bfi-Vl-BMd"/>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// Extensions.swift
3+
// KeyboardLayoutGuideExample
4+
//
5+
// Created by Max Konovalov on 27/11/2017.
6+
// Copyright © 2017 freshos. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension ViewController: UITextFieldDelegate {
12+
13+
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
14+
textField.resignFirstResponder()
15+
return false
16+
}
17+
18+
@IBAction func buttonTapped(_ sender: Any) {
19+
guard let textField = view.subviews.first as? UITextField else {
20+
return
21+
}
22+
if textField.isFirstResponder {
23+
textField.resignFirstResponder()
24+
} else {
25+
textField.becomeFirstResponder()
26+
}
27+
}
28+
29+
}
30+
31+
class InvertedButton: UIButton {
32+
33+
override var isHighlighted: Bool {
34+
didSet {
35+
updateBackgroundColor()
36+
}
37+
}
38+
39+
override func awakeFromNib() {
40+
super.awakeFromNib()
41+
updateBackgroundColor()
42+
}
43+
44+
override func tintColorDidChange() {
45+
super.tintColorDidChange()
46+
updateBackgroundColor()
47+
}
48+
49+
private func updateBackgroundColor() {
50+
backgroundColor = isHighlighted ? tintColor.withAlphaComponent(0.5) : tintColor
51+
}
52+
53+
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ override func viewDidLoad() {
2929
}
3030
```
3131

32+
If you add your view in Interface Builder, don't forget to enable the "**Remove at build time**" checkbox for the bottom constraint:
33+
34+
<img src="Images/constraint.png" width=258>
35+
3236
## Installation
3337

3438
### CocoaPods

0 commit comments

Comments
 (0)