Advertisement
Guest User

Untitled

a guest
May 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import UIKit
  2. import Eureka
  3. import SnapKit
  4.  
  5. class EditProfileAboutMeCell: Cell<String>, CellType, UITextViewDelegate {
  6.  
  7. private let titleLabel = UILabel()
  8. private let valueTextView = UITextView()
  9. private let bottomSeparator = UIView()
  10.  
  11. override func setup() {
  12. super.setup()
  13. addSubview(titleLabel)
  14. titleLabel.textColor = UIColor.gray
  15. titleLabel.snp.makeConstraints { (make) in
  16. make.top.equalToSuperview().offset(12)
  17. make.left.equalToSuperview().offset(15)
  18. make.width.equalToSuperview().multipliedBy(0.3)
  19. }
  20. addSubview(bottomSeparator)
  21. bottomSeparator.backgroundColor = UIColor.gray
  22. bottomSeparator.snp.makeConstraints { (make) in
  23. make.bottom.right.equalToSuperview()
  24. make.left.equalTo(titleLabel.snp.right).offset(8)
  25. make.height.equalTo(1)
  26. }
  27. addSubview(valueTextView)
  28. valueTextView.textColor = UIColor.black
  29. valueTextView.snp.makeConstraints { (make) in
  30. make.right.equalToSuperview()
  31. make.bottom.equalTo(bottomSeparator.snp.top)
  32. make.top.equalToSuperview()
  33. make.left.equalTo(titleLabel.snp.right).offset(8)
  34. }
  35.  
  36. selectionStyle = .none
  37. valueTextView.delegate = self
  38. }
  39.  
  40. override func update() {
  41. super.update()
  42.  
  43. guard let row = row as? EditProfileAboutMeRow else { return }
  44. row.title = nil
  45.  
  46. titleLabel.text = row.rowTitle
  47. valueTextView.text = row.value
  48. }
  49.  
  50. // MARK: UITextViewDelegate
  51. func textView(_ textView: UITextView,
  52. shouldChangeTextIn range: NSRange,
  53. replacementText text: String) -> Bool {
  54. guard let currentText = textView.text, let row = row as? EditProfileAboutMeRow else { return true }
  55. let newLength = currentText.count + text.count - range.length
  56. return newLength <= row.maximumLength
  57. }
  58.  
  59. // MARK: Text field helper
  60. @objc func textViewDidChange(_ textView: UITextView) {
  61. row.value = textView.text
  62. }
  63. }
  64.  
  65. final class EditProfileAboutMeRow: Row<EditProfileAboutMeCell>, RowType {
  66.  
  67. var maximumLength: Int = 150
  68. var placeholder: String?
  69. var rowTitle: String?
  70.  
  71. required init(tag: String?) {
  72. super.init(tag: tag)
  73. displayValueFor = nil
  74. }
  75.  
  76. init() {
  77. super.init(tag: nil)
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement