|
1 | | -# SafeAreaInputAccessoryViewWrapperView |
| 1 | + |
2 | 2 |
|
3 | | -[](https://travis-ci.org/jeffaburt/SafeAreaInputAccessoryViewWrapperView) |
| 3 | + |
| 4 | +[](http://cocoapods.org/pods/SafeAreaInputAccessoryViewWrapperView) |
4 | 5 | [](http://cocoapods.org/pods/SafeAreaInputAccessoryViewWrapperView) |
5 | 6 | [](http://cocoapods.org/pods/SafeAreaInputAccessoryViewWrapperView) |
6 | | -[](http://cocoapods.org/pods/SafeAreaInputAccessoryViewWrapperView) |
7 | 7 |
|
8 | | -## Example |
| 8 | +Description |
| 9 | +-------------- |
| 10 | + |
| 11 | +`SafeAreaInputAccessoryViewWrapperView` is useful for wrapping a view to be used as an `inputAccessoryView`. Without this, setting the view as an `inputAccessoryView` will ignore safe area layouts. For example, the Home screen indicator on iPhone X will battle for the same spot. This class ensures that the view respects safe area layouts and does not cover up system UI elements such as the Home screen indicator on iPhone X. |
| 12 | + |
| 13 | +**Works with iOS 9.0+ and Xcode 9.0.0+.** |
| 14 | + |
| 15 | +# Contents |
| 16 | +1. [Features](#features) |
| 17 | +2. [Usage](#usage) |
| 18 | +3. [Installation](#installation) |
| 19 | +6. [License](#license) |
| 20 | +7. [Contact](#contact) |
| 21 | + |
| 22 | +<a name="features"> Features </a> |
| 23 | +-------------- |
| 24 | + |
| 25 | +- [x] Works with all devices running iOS 9+. |
| 26 | +- [x] Respects `safeAreaLayoutGuide` on devices running iOS 11+. For example, the wrapped view is slid up to make room for the iPhone X Home screen indicator. |
| 27 | +- [x] Dynamically sets the wrapped view's height using autolayout constraints. No more setting frames manually! |
| 28 | +- [x] Example app with an `inputAccessoryView` that's always visible, even when the keyboard is closed. |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +<a name="usage"> Usage </a> |
| 34 | +-------------- |
| 35 | + |
| 36 | +1. Wrap any UIView/UIButton/UILabel/etc using `SafeAreaInputAccessoryViewWrapperView(for:)`: |
| 37 | + |
| 38 | +```swift |
| 39 | +SafeAreaInputAccessoryViewWrapperView(for: button) |
| 40 | +``` |
| 41 | + |
| 42 | +2. Store a reference to this somewhere in your class: |
| 43 | + |
| 44 | +```swift |
| 45 | +let button = UIButton(type: .system) |
| 46 | + |
| 47 | +lazy var wrappedButton: SafeAreaInputAccessoryViewWrapperView = { |
| 48 | + return SafeAreaInputAccessoryViewWrapperView(for: button) |
| 49 | +}() |
| 50 | +``` |
| 51 | + |
| 52 | +3. Return the reference in `inputAccessoryView`: |
| 53 | + |
| 54 | +```swift |
| 55 | +override var inputAccessoryView: UIView? { |
| 56 | + return wrappedButton |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +4. (Optional) Always show the `inputAccessoryView`, even when the keyboard is closed: |
| 61 | + |
| 62 | +```swift |
| 63 | +override var canBecomeFirstResponder: Bool { |
| 64 | + return true |
| 65 | +} |
| 66 | + |
| 67 | +override func viewDidLoad() { |
| 68 | + super.viewDidLoad() |
| 69 | + becomeFirstResponder() |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +<a name="installation"> Installation </a> |
| 74 | +-------------- |
9 | 75 |
|
10 | | -To run the example project, clone the repo, and run `pod install` from the Example directory first. |
| 76 | +### CocoaPods |
11 | 77 |
|
12 | | -## Requirements |
| 78 | +[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. |
13 | 79 |
|
14 | | -## Installation |
| 80 | +CocoaPods 0.36 adds supports for Swift and embedded frameworks. You can install it with the following command: |
15 | 81 |
|
16 | | -SafeAreaInputAccessoryViewWrapperView is available through [CocoaPods](http://cocoapods.org). To install |
17 | | -it, simply add the following line to your Podfile: |
| 82 | +```bash |
| 83 | +$ gem install cocoapods |
| 84 | +``` |
| 85 | + |
| 86 | +To integrate `SafeAreaInputAccessoryViewWrapperView` into your Xcode project using CocoaPods, specify it in your `Podfile`: |
18 | 87 |
|
19 | 88 | ```ruby |
20 | 89 | pod 'SafeAreaInputAccessoryViewWrapperView' |
21 | 90 | ``` |
22 | 91 |
|
23 | | -## Author |
| 92 | +Then, run the following command: |
| 93 | + |
| 94 | +```bash |
| 95 | +$ pod install |
| 96 | +``` |
| 97 | + |
| 98 | +In case Xcode complains (<i>"Cannot load underlying module for SafeAreaInputAccessoryViewWrapperView"</i>) go to Product and choose Clean (or simply press <kbd>⇧</kbd><kbd>⌘</kbd><kbd>K</kbd>). |
| 99 | + |
| 100 | +### Manually |
| 101 | + |
| 102 | +If you prefer not to use CocoaPods, you can integrate `SafeAreaInputAccessoryViewWrapperView` into your project manually. |
| 103 | + |
| 104 | +<a name="license"> License </a> |
| 105 | +-------------- |
24 | 106 |
|
25 | | -jeffaburt, jburt1992@gmail.com |
| 107 | +`SafeAreaInputAccessoryViewWrapperView` is developed by [Jeff Burt](https://www.linkedin.com/in/jeffaburt) at [StockX](https://stockx.com) and is released under the MIT license. See the `LICENSE` file for details. |
26 | 108 |
|
27 | | -## License |
| 109 | +<a name="contact"> Contact </a> |
| 110 | +-------------- |
28 | 111 |
|
29 | | -SafeAreaInputAccessoryViewWrapperView is available under the MIT license. See the LICENSE file for more info. |
| 112 | +Feel free to follow me on [my personal Twitter account](https://twitter.com/jeffburtjr). If you find any problems with the project or have ideas to enhance it, feel free to open a GitHub issue and/or create a pull request. |
0 commit comments