LNAutoSizeTextView.swift 797 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // LNAutoSizeTextView.swift
  3. // Lanu
  4. //
  5. // Created by OneeChan on 2025/11/14.
  6. //
  7. import Foundation
  8. import UIKit
  9. import SnapKit
  10. class LNAutoSizeTextView: UITextView {
  11. override var contentSize: CGSize {
  12. didSet {
  13. guard contentSize.height > 0 else { return }
  14. snp.updateConstraints { make in
  15. make.height.equalTo(contentSize.height).priority(.medium)
  16. }
  17. }
  18. }
  19. override init(frame: CGRect, textContainer: NSTextContainer?) {
  20. super.init(frame: frame, textContainer: textContainer)
  21. snp.makeConstraints { make in
  22. make.height.equalTo(0).priority(.medium)
  23. }
  24. }
  25. required init?(coder: NSCoder) {
  26. fatalError("init(coder:) has not been implemented")
  27. }
  28. }