DesignableNavigationBar.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // Created by Jake Lin on 12/10/15.
  3. // Copyright © 2015 IBAnimatable. All rights reserved.
  4. //
  5. import UIKit
  6. @IBDesignable
  7. open class DesignableNavigationBar: UINavigationBar, NavigationBarDesignable, GradientDesignable {
  8. // MARK: - NavigationBarDesignable
  9. @IBInspectable open var solidColor: Bool = false
  10. // MARK: - GradientDesignable
  11. open var gradientMode: GradientMode = .linear
  12. @IBInspectable var _gradientMode: String? {
  13. didSet {
  14. gradientMode = GradientMode(string: _gradientMode) ?? .linear
  15. }
  16. }
  17. @IBInspectable open var startColor: UIColor?
  18. @IBInspectable open var endColor: UIColor?
  19. open var predefinedGradient: GradientType?
  20. @IBInspectable var _predefinedGradient: String? {
  21. didSet {
  22. predefinedGradient = GradientType(string: _predefinedGradient)
  23. }
  24. }
  25. open var startPoint: GradientStartPoint = .top
  26. @IBInspectable var _startPoint: String? {
  27. didSet {
  28. startPoint = GradientStartPoint(string: _startPoint, default: .top)
  29. }
  30. }
  31. // MARK: - Lifecycle
  32. open override func prepareForInterfaceBuilder() {
  33. super.prepareForInterfaceBuilder()
  34. configureInspectableProperties()
  35. }
  36. open override func awakeFromNib() {
  37. super.awakeFromNib()
  38. configureInspectableProperties()
  39. }
  40. open override func layoutSubviews() {
  41. super.layoutSubviews()
  42. configureAfterLayoutSubviews()
  43. }
  44. // MARK: - Private
  45. fileprivate func configureInspectableProperties() {
  46. configureNavigationBar()
  47. configureGradient()
  48. }
  49. fileprivate func configureAfterLayoutSubviews() {
  50. configureGradient()
  51. }
  52. }