Giter VIP home page Giter VIP logo

messageviewcontroller's Introduction

Installation

Just add MessageViewController to your Podfile and install. Done!

pod 'MessageViewController'

Setup

You must subclass MessageViewController.

import MessageViewController

class ViewController: MessageViewController {
  // ...
}

Finish setup using a UIScrollView. Remember this can also be a UITableView or UICollectionView.

func viewDidLoad() {
  super.viewDidLoad()
  setup(scrollView: scrollView)
}

Customizations

You can customize any part of the UI that you want!

// Border between the text view and the scroll view
borderColor = .lightGray

// Change the appearance of the text view and its content
messageView.inset = UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16)
messageView.textView.placeholderText = "New message..."
messageView.textView.placeholderTextColor = .lightGray
messageView.font = .systemFont(ofSize: 17)

// Setup the button using text or an icon
messageView.set(buttonTitle: "Send", for: .normal)
messageView.addButton(target: self, action: #selector(onButton))
messageView.buttonTint = .blue

// Set custom attributes for an autocompleted string
let tintColor = .blue
messageAutocompleteController.autocompleteTextAttributes = ["@": [.font: UIFont.preferredFont(forTextStyle: .body), .foregroundColor: tintColor, .backgroundColor: tintColor.withAlphaComponent(0.1)]]

Autocomplete

The base view controller uses a MessageAutocompleteController control to handle text autocompletion.

This control uses a plain UITableView to display its autocomplete. Add a dataSource and delegate to display and handle interactions.

let tableView = messageAutocompleteController.tableView
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.dataSource = self
tableView.delegate = self

Then register for autocomplete prefixes you want to respond to and set a delegate to handle when a prefix is found.

messageAutocompleteController.register(prefix: "@")
messageAutocompleteController.delegate = self

Your delegate needs to implement just one method.

func didFind(controller: MessageAutocompleteController, prefix: String, word: String) {
  // filter your data
  controller.show(true)
}

Note: You can perform asyncronous autocomplete searches. Just be sure to call messageAutocompleteController.show() when finished.

Acknowledgements

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.