ValidatingIndicatorView.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // ValidatingIndicatorView.swift
  3. // Loop
  4. //
  5. // Created by Nate Racklyeft on 7/2/16.
  6. // Copyright © 2016 Nathan Racklyeft. All rights reserved.
  7. //
  8. import UIKit
  9. private let Margin: CGFloat = 8
  10. public final class ValidatingIndicatorView: UIView {
  11. let indicatorView = UIActivityIndicatorView(style: .default)
  12. let label = UILabel()
  13. public override init(frame: CGRect) {
  14. super.init(frame: frame)
  15. label.font = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.headline)
  16. label.text = LocalizedString("Verifying", comment: "Label indicating validation is occurring")
  17. label.sizeToFit()
  18. addSubview(indicatorView)
  19. addSubview(label)
  20. self.frame.size = intrinsicContentSize
  21. setNeedsLayout()
  22. indicatorView.startAnimating()
  23. }
  24. required init?(coder aDecoder: NSCoder) {
  25. fatalError("init(coder:) has not been implemented")
  26. }
  27. public override func layoutSubviews() {
  28. super.layoutSubviews()
  29. // Center the label in the bounds so it appears aligned, then let the indicator view hang from the left side
  30. label.frame = bounds
  31. indicatorView.center.y = bounds.midY
  32. indicatorView.frame.origin.x = -indicatorView.frame.size.width - Margin
  33. }
  34. public override var intrinsicContentSize : CGSize {
  35. return label.intrinsicContentSize
  36. }
  37. }