AdditionalFormTextLabel.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import UIKit
  15. class AdditionalFormTextLabel: UILabel {
  16. var topInset = 10.0
  17. var bottomInset = 15.0
  18. var leftInset = 10.0
  19. var rightInset = 10.0
  20. override func drawText(in rect: CGRect) {
  21. let insets = UIEdgeInsets(
  22. top: topInset,
  23. left: leftInset,
  24. bottom: bottomInset,
  25. right: rightInset
  26. )
  27. super.drawText(in: rect.inset(by: insets))
  28. }
  29. override var intrinsicContentSize: CGSize {
  30. let size = super.intrinsicContentSize
  31. return CGSize(width: size.width + leftInset + rightInset,
  32. height: size.height + topInset + bottomInset)
  33. }
  34. override var bounds: CGRect {
  35. didSet {
  36. preferredMaxLayoutWidth = bounds.width - (leftInset + rightInset)
  37. }
  38. }
  39. }