@@ -7,18 +7,16 @@ import UIKit
77
88class CommandBarButtonGroupView : UIView {
99 let buttons : [ CommandBarButton ]
10+ let title : String ?
1011
11- init ( buttons: [ CommandBarButton ] , tokenSet: CommandBarTokenSet ) {
12+ init ( buttons: [ CommandBarButton ] , title : String ? , tokenSet: CommandBarTokenSet ) {
1213 self . buttons = buttons
14+ self . title = title
1315 self . tokenSet = tokenSet
1416
1517 super. init ( frame: . zero)
1618 translatesAutoresizingMaskIntoConstraints = false
1719
18- clipsToBounds = true
19- layer. cornerRadius = tokenSet [ . groupBorderRadius] . float
20- layer. cornerCurve = . continuous
21-
2220 configureHierarchy ( )
2321 applyInsets ( )
2422 hideGroupIfNeeded ( )
@@ -32,7 +30,7 @@ class CommandBarButtonGroupView: UIView {
3230 /// Hides the group view if all the views inside the `stackView` are hidden
3331 func hideGroupIfNeeded( ) {
3432 var allViewsHidden = true
35- for view in stackView . arrangedSubviews {
33+ for view in buttonStackView . arrangedSubviews {
3634 if !view. isHidden {
3735 allViewsHidden = false
3836 break
@@ -44,21 +42,42 @@ class CommandBarButtonGroupView: UIView {
4442
4543 var equalWidthButtons : Bool = false {
4644 didSet {
47- stackView . distribution = equalWidthButtons ? . fillEqually : . fill
45+ buttonStackView . distribution = equalWidthButtons ? . fillEqually : . fill
4846 }
4947 }
5048
51- private lazy var stackView : UIStackView = {
49+ private lazy var buttonStackView : UIStackView = {
5250 let stackView = UIStackView ( arrangedSubviews: buttons)
5351 stackView. translatesAutoresizingMaskIntoConstraints = false
5452 stackView. axis = . horizontal
5553 stackView. spacing = CommandBarTokenSet . itemInterspace
5654
55+ stackView. clipsToBounds = true
56+ stackView. layer. cornerRadius = tokenSet [ . groupBorderRadius] . float
57+ stackView. layer. cornerCurve = . continuous
5758 return stackView
5859 } ( )
5960
61+ private lazy var groupLabel : Label = {
62+ let label = Label ( textStyle: . caption2, colorStyle: . regular)
63+ label. text = title
64+ label. translatesAutoresizingMaskIntoConstraints = false
65+ label. setContentHuggingPriority ( . required, for: . vertical)
66+ label. lineBreakMode = . byClipping
67+ return label
68+ } ( )
69+
6070 private func configureHierarchy( ) {
71+ let stackView = UIStackView ( )
72+ stackView. translatesAutoresizingMaskIntoConstraints = false
73+ stackView. axis = . vertical
74+
75+ stackView. addArrangedSubview ( buttonStackView)
76+ if title != nil {
77+ stackView. addArrangedSubview ( groupLabel)
78+ }
6179 addSubview ( stackView)
80+
6281 NSLayoutConstraint . activate ( [
6382 stackView. topAnchor. constraint ( equalTo: topAnchor) ,
6483 stackView. leadingAnchor. constraint ( equalTo: leadingAnchor) ,
0 commit comments