@@ -40,6 +40,16 @@ open class NativeProfileHeaderView: SPView {
4040 $0. textAlignment = . center
4141 $0. adjustsFontSizeToFitWidth = true
4242 $0. minimumScaleFactor = 0.5
43+ $0. text = nil
44+ }
45+
46+ public let namePlaceholderLabel = SPLabel ( ) . do {
47+ $0. font = UIFont . preferredFont ( forTextStyle: . title2, weight: . semibold, addPoints: 2 )
48+ $0. textColor = . secondaryLabel
49+ $0. numberOfLines = 1
50+ $0. textAlignment = . center
51+ $0. adjustsFontSizeToFitWidth = true
52+ $0. minimumScaleFactor = 0.5
4353 $0. text = . space
4454 }
4555
@@ -60,13 +70,35 @@ open class NativeProfileHeaderView: SPView {
6070
6171 open override func commonInit( ) {
6272 super. commonInit ( )
63- backgroundColor = . systemBackground
64- extendView. backgroundColor = backgroundColor
65- addSubviews ( [ extendView, avatarView, nameLabel, emailButton] )
73+ backgroundColor = . clear
74+ addSubviews ( [ extendView, avatarView, nameLabel, namePlaceholderLabel, emailButton] )
75+
76+ layoutMargins = . init(
77+ top: NativeLayout . Spaces. default_half,
78+ left: NativeLayout . Spaces. default_double,
79+ bottom: NativeLayout . Spaces. default_half,
80+ right: NativeLayout . Spaces. default_double
81+ )
82+ }
83+
84+ // MARK: - Ovveride
85+
86+ open override var backgroundColor : UIColor ? {
87+ didSet {
88+ extendView. backgroundColor = backgroundColor
89+ }
6690 }
6791
6892 // MARK: - Layout
6993
94+ private var usingNameLabel : SPLabel {
95+ if nameLabel. text == nil {
96+ return namePlaceholderLabel
97+ } else {
98+ return nameLabel
99+ }
100+ }
101+
70102 open override func layoutSubviews( ) {
71103 super. layoutSubviews ( )
72104 extendView. frame = . init( x: . zero, maxY: . zero, width: frame. width, height: 1000 )
@@ -77,12 +109,18 @@ open class NativeProfileHeaderView: SPView {
77109
78110 nameLabel. layoutDynamicHeight ( width: layoutWidth)
79111 nameLabel. setXCenter ( )
80- nameLabel. frame. origin. y = avatarView. frame. maxY + 8
112+ nameLabel. frame. origin. y = avatarView. frame. maxY + NativeLayout. Spaces. default_half
113+
114+ namePlaceholderLabel. layoutDynamicHeight ( width: layoutWidth)
115+ namePlaceholderLabel. setXCenter ( )
116+ namePlaceholderLabel. frame. origin. y = nameLabel. frame. origin. y
117+
118+ nameLabel. isHidden = !( nameLabel == usingNameLabel)
119+ namePlaceholderLabel. isHidden = !( namePlaceholderLabel == usingNameLabel)
81120
82121 emailButton. sizeToFit ( )
83- emailButton. frame. setWidth ( nameLabel. frame. width)
84122 emailButton. setXCenter ( )
85- emailButton. frame. origin. y = nameLabel . frame. maxY + 2
123+ emailButton. frame. origin. y = usingNameLabel . frame. maxY
86124 }
87125
88126 open override func sizeThatFits( _ size: CGSize ) -> CGSize {
0 commit comments