Skip to content

Instantly share code, notes, and snippets.

@b-onc
Last active April 15, 2020 14:05
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 b-onc/5778255826b21cd6930e3556bb2b7cde to your computer and use it in GitHub Desktop.
Save b-onc/5778255826b21cd6930e3556bb2b7cde to your computer and use it in GitHub Desktop.
import UIKit
import StreamChat
import RxSwift
class MessagesViewController: ChatViewController {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.largeTitleDisplayMode = .never
setupNavigationBar()
}
private func setupNavigationBar() {
guard let channel = presenter?.channel else {
return
}
navigationItem.rightBarButtonItem = nil
let chatNavigationTitleView = ChatNavigationTitleView()
chatNavigationTitleView.update(title: channel.name ?? "", imageURL: channel.imageURL)
navigationItem.titleView = chatNavigationTitleView
}
}
class ChatNavigationTitleView: UIView {
private let avatar = AvatarView(cornerRadius: 12)
private let titleLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupUI()
}
private func setupUI() {
addSubview(avatar)
avatar.translatesAutoresizingMaskIntoConstraints = false
addSubview(titleLabel)
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.font = .systemFont(ofSize: 12)
NSLayoutConstraint.activate([
avatar.centerXAnchor.constraint(equalTo: centerXAnchor),
avatar.topAnchor.constraint(equalTo: topAnchor),
avatar.leftAnchor.constraint(equalTo: leftAnchor),
avatar.rightAnchor.constraint(equalTo: rightAnchor),
titleLabel.topAnchor.constraint(equalTo: avatar.bottomAnchor, constant: 0),
titleLabel.centerXAnchor.constraint(equalTo: avatar.centerXAnchor),
titleLabel.bottomAnchor.constraint(equalTo: bottomAnchor),
])
}
func update(title: String, imageURL: URL?) {
titleLabel.text = title
titleLabel.sizeToFit()
avatar.update(with: imageURL, name: title, baseColor: .clear)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment