SeparatorLine.swift 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // SeparatorLine.swift
  3. // InputBarAccessoryView
  4. //
  5. // Copyright © 2017-2019 Nathan Tannar.
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in all
  15. // copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. // SOFTWARE.
  24. //
  25. // Created by Nathan Tannar on 10/4/17.
  26. //
  27. import UIKit
  28. /**
  29. A UIView thats intrinsicContentSize is overrided so an exact height can be specified
  30. ## Important Notes ##
  31. 1. Default height is 1.0
  32. 2. Default backgroundColor is UIColor.lightGray
  33. 3. Intended to be used in an `InputStackView`
  34. */
  35. open class SeparatorLine: UIView {
  36. // MARK: - Properties
  37. /// The height of the line
  38. open var height: CGFloat = 1.0 {
  39. didSet {
  40. constraints.filter { $0.identifier == "height" }.forEach { $0.constant = height } // Assumes constraint was given an identifier
  41. invalidateIntrinsicContentSize()
  42. }
  43. }
  44. open override var intrinsicContentSize: CGSize {
  45. return CGSize(width: super.intrinsicContentSize.width, height: height)
  46. }
  47. // MARK: - Initialization
  48. public override init(frame: CGRect) {
  49. super.init(frame: frame)
  50. setup()
  51. }
  52. required public init?(coder aDecoder: NSCoder) {
  53. super.init(coder: aDecoder)
  54. setup()
  55. }
  56. /// Sets up the default properties
  57. open func setup() {
  58. backgroundColor = .lightGray
  59. translatesAutoresizingMaskIntoConstraints = false
  60. setContentHuggingPriority(.defaultHigh, for: .vertical)
  61. }
  62. }