@@ -12,7 +12,7 @@ public final class CHeaderView: UICollectionReusableView {
1212 // MARK: - Title Label
1313 /* A UILabel used to display the title of the section header.
1414 It is styled with bold font and truncated if too long.*/
15- private let titleLabel : UILabel = {
15+ private lazy var titleLabel : UILabel = {
1616 let lbl = UILabel ( )
1717 lbl. translatesAutoresizingMaskIntoConstraints = false
1818 lbl. font = . boldSystemFont( ofSize: 20 )
@@ -24,6 +24,17 @@ public final class CHeaderView: UICollectionReusableView {
2424 return lbl
2525 } ( )
2626
27+ // MARK: - Title Icon
28+ /* A UIImageView used to display an optional iconnext to the section header title.
29+ Supports both system images and asset-based images.Hidden by default when no icon is provided. */
30+ private lazy var titleIcon : UIImageView = {
31+ let imageView = UIImageView ( )
32+ imageView. translatesAutoresizingMaskIntoConstraints = false
33+ imageView. contentMode = . scaleAspectFit
34+ imageView. isHidden = true
35+ return imageView
36+ } ( )
37+
2738 // MARK: - Button and Stack References
2839 /* Variables to hold the stack views and button callback.
2940 buttonTypes keeps track of the available buttons.*/
@@ -68,6 +79,7 @@ extension CHeaderView {
6879 Dynamically creates stack views and separators.*/
6980 public func configure(
7081 with cellItem: ( title: String ,
82+ icon: TitleIcon ? ,
7183 sizeType: SectionSizeType ,
7284 buttonTypes: [ TitleForSectionButtonType ] ? ) ,
7385 onTap: @escaping ( TitleForSectionButtonType ) -> Void
@@ -76,6 +88,19 @@ extension CHeaderView {
7688 titleLabel. text = cellItem. title
7789 titleLabel. font = . boldSystemFont( ofSize: cellItem. sizeType. size)
7890
91+ if let icon = cellItem. icon {
92+ switch icon. image {
93+ case . systemImage( let name) :
94+ titleIcon. image = UIImage ( systemName: name)
95+ case . imageAsstes( let name) :
96+ titleIcon. image = UIImage ( named: name)
97+ }
98+ titleIcon. tintColor = icon. tintColor
99+ titleIcon. isHidden = false
100+ } else {
101+ titleIcon. isHidden = true
102+ }
103+
79104 //Determine if the header should be visible based on title and buttons.
80105 let hasTitle = !( cellItem. title. isEmpty)
81106 let hasButtons = !( cellItem. buttonTypes? . isEmpty ?? true )
@@ -130,8 +155,8 @@ extension CHeaderView {
130155
131156 self . buttonStack = buttonStack
132157
133- // Main stack contains the title label and button stack, horizontally aligned.
134- let mainStack = UIStackView ( arrangedSubviews: [ titleLabel, buttonStack] )
158+ // Main stack contains the icon title label and button stack, horizontally aligned.
159+ let mainStack = UIStackView ( arrangedSubviews: [ titleIcon , titleLabel, buttonStack] )
135160 mainStack. axis = . horizontal
136161 mainStack. alignment = . center
137162 mainStack. spacing = 8
@@ -148,6 +173,13 @@ extension CHeaderView {
148173 mainStack. bottomAnchor. constraint ( equalTo: bottomAnchor)
149174 ] )
150175
176+
177+ NSLayoutConstraint . activate ( [
178+ titleIcon. heightAnchor. constraint ( equalToConstant: 20 ) ,
179+ titleIcon. widthAnchor. constraint ( equalToConstant: 20 )
180+
181+ ] )
182+
151183 // Set content hugging and compression priorities to ensure proper layout behavior.
152184 buttonStack. setContentHuggingPriority ( . required, for: . horizontal)
153185 titleLabel. setContentHuggingPriority ( . defaultLow, for: . horizontal)
0 commit comments