VLCFileServerSectionTableHeaderView.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*****************************************************************************
  2. * VLCFileServerSectionTableHeaderView.swift
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2018 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Author: Carola Nitz <caro # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. import Foundation
  13. @objc protocol VLCFileServerSectionTableHeaderViewDelegate: NSObjectProtocol {
  14. func connectToServer()
  15. }
  16. class VLCFileServerSectionTableHeaderView: VLCSectionTableHeaderView {
  17. @objc static let identifier = "VLCFileServerSectionTableHeaderView"
  18. @objc weak var delegate: VLCFileServerSectionTableHeaderViewDelegate?
  19. var layoutConstraints: [NSLayoutConstraint]?
  20. lazy var connectButton: UIButton = {
  21. let connectButton = UIButton(type: .system)
  22. connectButton.setTitle(NSLocalizedString("BUTTON_CONNECT", comment: ""), for: .normal)
  23. connectButton.titleLabel?.font = UIFont.systemFont(ofSize: 17)
  24. connectButton.titleLabel?.textColor = PresentationTheme.current.colors.orangeUI
  25. connectButton.translatesAutoresizingMaskIntoConstraints = false
  26. connectButton.addTarget(self, action: #selector(connectButtonDidPress), for: .touchUpInside)
  27. contentView.addSubview(connectButton)
  28. return connectButton
  29. }()
  30. override func setupUI() {
  31. super.setupUI()
  32. textLabel?.text = NSLocalizedString("FILE_SERVER", comment: "")
  33. }
  34. //Before layoutSubviews textlabel doesn't have a superview
  35. override func layoutSubviews() {
  36. super.layoutSubviews()
  37. if layoutConstraints == nil {
  38. layoutConstraints = [
  39. connectButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
  40. connectButton.firstBaselineAnchor.constraint(equalTo: textLabel!.firstBaselineAnchor)
  41. ]
  42. NSLayoutConstraint.activate(layoutConstraints!)
  43. }
  44. }
  45. @objc func connectButtonDidPress() {
  46. delegate?.connectToServer()
  47. }
  48. override func prepareForReuse() {
  49. super.prepareForReuse()
  50. //Text gets set to nil in prepareForReuse so we set it again
  51. textLabel?.text = NSLocalizedString("FILE_SERVER", comment: "")
  52. }
  53. }