|
1 |
| -COMING SOON |
| 1 | +<p align="center"> |
| 2 | + <img src="/animation.gif" /> |
| 3 | +</p> |
| 4 | + |
| 5 | +| | Main Features | |
| 6 | +----------|----------------- |
| 7 | +📱 | iPhone X support |
| 8 | +🐦 | Built in Swift |
| 9 | +💅 | Fully customizable |
| 10 | +🛠 | Decoupled API |
| 11 | +🦅 | Used in [GitHawk](https://github.com/rnystrom/githawk) |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +Just add `MessageViewController` to your Podfile and install. Done! |
| 16 | + |
| 17 | +``` |
| 18 | +pod 'MessageViewController' |
| 19 | +``` |
| 20 | + |
| 21 | +## Setup |
| 22 | + |
| 23 | +You must subclass `MessageViewController`. |
| 24 | + |
| 25 | +```swift |
| 26 | +import MessageViewController |
| 27 | + |
| 28 | +class ViewController: MessageViewController { |
| 29 | + // ... |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +Finish setup using a `UIScrollView`. Remember this can also be a `UITableView` or `UICollectionView`. |
| 34 | + |
| 35 | +```swift |
| 36 | +func viewDidLoad() { |
| 37 | + super.viewDidLoad() |
| 38 | + setup(scrollView: scrollView) |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +## Customizations |
| 43 | + |
| 44 | +You can customize any part of the UI that you want! |
| 45 | + |
| 46 | +```swift |
| 47 | +// Border between the text view and the scroll view |
| 48 | +borderColor = .lightGray |
| 49 | + |
| 50 | +// Change the appearance of the text view and its content |
| 51 | +messageView.inset = UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16) |
| 52 | +messageView.textView.placeholderText = "New message..." |
| 53 | +messageView.textView.placeholderTextColor = .lightGray |
| 54 | +messageView.font = UIFont.systemFont(ofSize: 17) |
| 55 | + |
| 56 | +// Setup the button using text or an icon |
| 57 | +messageView.set(buttonTitle: "Send", for: .normal) |
| 58 | +messageView.addButton(target: self, action: #selector(onButton)) |
| 59 | +messageView.buttonTint = .blue |
| 60 | +``` |
| 61 | + |
| 62 | +## Autocomplete |
| 63 | + |
| 64 | +The base view controller uses a `MessageAutocompleteController` control to handle text autocompletion. |
| 65 | + |
| 66 | +This control uses a plain `UITableView` to display its autocomplete. Add a `dataSource` and `delegate` to display and handle interactions. |
| 67 | + |
| 68 | +```swift |
| 69 | +messageAutocompleteController.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") |
| 70 | +messageAutocompleteController.tableView.dataSource = self |
| 71 | +messageAutocompleteController.tableView.delegate = self |
| 72 | +``` |
| 73 | + |
| 74 | +Then register for autocomplete prefixes you want to respond to and set a `delegate` to handle when a prefix is found. |
| 75 | + |
| 76 | +```swift |
| 77 | +messageAutocompleteController.register(prefix: "@") |
| 78 | +messageAutocompleteController.delegate = self |
| 79 | +``` |
| 80 | + |
| 81 | +Your delegate needs to implement just one method. |
| 82 | + |
| 83 | +```swift |
| 84 | +func didFind(controller: MessageAutocompleteController, prefix: String, word: String) { |
| 85 | + // filter your data |
| 86 | + controller.show(true) |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +> **Note:** You can perform asyncronous autocomplete searches. Just be sure to call `messageAutocompleteController.show()` when finished. |
| 91 | +
|
| 92 | +## Acknowledgements |
| 93 | + |
| 94 | +- Heavy inspiration from [SlackTextViewController](https://github.com/slackhq/SlackTextViewController) |
| 95 | +- Created with ❤️ by [Ryan Nystrom](https://twitter.com/_ryannystrom) |
0 commit comments