Skip to content

Instantly share code, notes, and snippets.

@zontan
Created September 9, 2020 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zontan/d73570fcf284e238a96e103e2b65d1b7 to your computer and use it in GitHub Desktop.
Save zontan/d73570fcf284e238a96e103e2b65d1b7 to your computer and use it in GitHub Desktop.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
chatTableView = UITableView(frame: .zero)
view.addSubview(chatTableView)
chatTableView.delegate = self
chatTableView.dataSource = self
chatTableView.backgroundColor = UIColor.clear
chatTableView.translatesAutoresizingMaskIntoConstraints = false
chatTableView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
chatTableView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.4).isActive = true
chatTableView.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.5).isActive = true
chatTableView.register(UITableViewCell.self, forCellReuseIdentifier: "chatCell")
chatTableView.keyboardDismissMode = .onDrag
collectionView.keyboardDismissMode = .interactive
let chatField = UITextField(frame: .zero)
view.addSubview(chatField)
chatField.delegate = self
chatField.backgroundColor = UIColor.white
chatField.translatesAutoresizingMaskIntoConstraints = false
chatField.topAnchor.constraint(equalTo: chatTableView.bottomAnchor).isActive = true
chatField.leftAnchor.constraint(equalTo: chatTableView.leftAnchor).isActive = true
chatField.widthAnchor.constraint(equalTo: chatTableView.widthAnchor).isActive = true
chatField.heightAnchor.constraint(equalToConstant: 40).isActive = true
bottomConstraint = view.bottomAnchor.constraint(equalTo: chatField.bottomAnchor, constant: 110)
bottomConstraint?.isActive = true
NotificationCenter.default.addObserver(self, selector: #selector(ChatViewController.keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(ChatViewController.keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment