InputStackView.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. MIT License
  3. Copyright (c) 2017-2018 MessageKit
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. */
  20. import UIKit
  21. /**
  22. A UIStackView that's intended for holding `InputItem`s
  23. ## Important Notes ##
  24. 1. Default alignment is .fill
  25. 2. Default distribution is .fill
  26. 3. The distribution property needs to be based on its arranged subviews intrinsicContentSize so it is not recommended to change it
  27. */
  28. open class InputStackView: UIStackView {
  29. /// The stack view position in the MessageInputBar
  30. ///
  31. /// - left: Left Stack View
  32. /// - right: Bottom Stack View
  33. /// - bottom: Left Stack View
  34. /// - top: Top Stack View
  35. public enum Position {
  36. case left, right, bottom, top
  37. }
  38. // MARK: Initialization
  39. public convenience init(axis: NSLayoutConstraint.Axis, spacing: CGFloat) {
  40. self.init(frame: .zero)
  41. self.axis = axis
  42. self.spacing = spacing
  43. }
  44. public override init(frame: CGRect) {
  45. super.init(frame: frame)
  46. setup()
  47. }
  48. required public init(coder: NSCoder) {
  49. super.init(coder: coder)
  50. }
  51. // MARK: - Setup
  52. /// Sets up the default properties
  53. open func setup() {
  54. translatesAutoresizingMaskIntoConstraints = false
  55. distribution = .fill
  56. alignment = .bottom
  57. }
  58. }