@@ -9,12 +9,14 @@ public class TextHeaderView : UITableViewHeaderFooterView
9
9
{
10
10
public UILabel Label { get ; set ; }
11
11
List < NSLayoutConstraint > _constraints = new List < NSLayoutConstraint > ( ) ;
12
+ NSLayoutConstraint _leftConstraint ;
12
13
UIEdgeInsets _curPadding ;
14
+ UITableView _tableView ;
13
15
LayoutAlignment _curAlignment ;
14
16
bool _isInitialized ;
15
17
16
18
public TextHeaderView ( IntPtr handle ) : base ( handle )
17
- {
19
+ {
18
20
Label = new UILabel ( ) ;
19
21
Label . Lines = 1 ;
20
22
Label . LineBreakMode = UILineBreakMode . TailTruncation ;
@@ -24,7 +26,23 @@ public TextHeaderView(IntPtr handle): base(handle)
24
26
25
27
this . BackgroundView = new UIView ( ) ;
26
28
}
27
- public void Initialzie ( UIEdgeInsets padding , LayoutAlignment align )
29
+
30
+ public override void LayoutSubviews ( )
31
+ {
32
+ base . LayoutSubviews ( ) ;
33
+
34
+ if ( _leftConstraint != null )
35
+ {
36
+ _leftConstraint . Active = false ;
37
+ _leftConstraint . Dispose ( ) ;
38
+ _leftConstraint = null ;
39
+ }
40
+
41
+ _leftConstraint = Label . LeftAnchor . ConstraintEqualTo ( LeftAnchor , _curPadding . Left + _tableView . SafeAreaInsets . Left ) ;
42
+ _leftConstraint . Active = true ;
43
+ }
44
+
45
+ public void Initialzie ( UIEdgeInsets padding , LayoutAlignment align , UITableView tableView )
28
46
{
29
47
if ( _isInitialized && _curPadding == padding && align == _curAlignment )
30
48
{
@@ -37,8 +55,8 @@ public void Initialzie(UIEdgeInsets padding, LayoutAlignment align)
37
55
c . Dispose ( ) ;
38
56
}
39
57
_constraints . Clear ( ) ;
40
-
41
- _constraints . Add ( Label . LeftAnchor . ConstraintEqualTo ( this . LeftAnchor , padding . Left ) ) ;
58
+
59
+ // _constraints.Add(Label.LeftAnchor.ConstraintEqualTo(this.LeftAnchor, padding.Left + safeAreaInsets .Left));
42
60
_constraints . Add ( Label . RightAnchor . ConstraintEqualTo ( this . RightAnchor , - padding . Right ) ) ;
43
61
44
62
if ( align == LayoutAlignment . Start )
@@ -61,6 +79,7 @@ public void Initialzie(UIEdgeInsets padding, LayoutAlignment align)
61
79
62
80
_curPadding = padding ;
63
81
_curAlignment = align ;
82
+ _tableView = tableView ;
64
83
_isInitialized = true ;
65
84
}
66
85
@@ -70,10 +89,13 @@ protected override void Dispose(bool disposing)
70
89
if ( disposing )
71
90
{
72
91
_constraints . ForEach ( c => c . Dispose ( ) ) ;
92
+ _leftConstraint ? . Dispose ( ) ;
93
+ _leftConstraint = null ;
73
94
Label ? . Dispose ( ) ;
74
95
Label = null ;
75
96
BackgroundView ? . Dispose ( ) ;
76
97
BackgroundView = null ;
98
+ _tableView = null ;
77
99
}
78
100
}
79
101
}
0 commit comments