@@ -44,7 +44,10 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon
4444
4545 let layout = UICollectionViewFlowLayout ( )
4646 let sectionInset : CGFloat = spacing
47- layout. sectionInset = UIEdgeInsets ( top: sectionInset, left: sectionInset, bottom: sectionInset, right: sectionInset)
47+ layout. sectionInset = UIEdgeInsets ( top: sectionInset,
48+ left: sectionInset,
49+ bottom: sectionInset,
50+ right: sectionInset)
4851 layout. minimumInteritemSpacing = spacing
4952 layout. minimumLineSpacing = spacing
5053
@@ -102,41 +105,10 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon
102105 titleLabel. translatesAutoresizingMaskIntoConstraints = false
103106
104107 containerView. addSubview ( titleLabel)
105- _ = NSLayoutConstraint (
106- item: titleLabel,
107- attribute: . leading,
108- relatedBy: . equal,
109- toItem: containerView,
110- attribute: . leading,
111- multiplier: 1.0 ,
112- constant: titleInsets. left) . isActive = true
113-
114- _ = NSLayoutConstraint (
115- item: titleLabel,
116- attribute: . trailing,
117- relatedBy: . equal,
118- toItem: containerView,
119- attribute: . trailing,
120- multiplier: 1.0 ,
121- constant: 0 ) . isActive = true
122-
123- _ = NSLayoutConstraint (
124- item: titleLabel,
125- attribute: . bottom,
126- relatedBy: . equal,
127- toItem: containerView,
128- attribute: . bottom,
129- multiplier: 1.0 ,
130- constant: - titleInsets. bottom) . isActive = true
131-
132- _ = NSLayoutConstraint (
133- item: titleLabel,
134- attribute: . height,
135- relatedBy: . equal,
136- toItem: nil ,
137- attribute: . notAnAttribute,
138- multiplier: 1.0 ,
139- constant: titleSize. height) . isActive = true
108+ constrainLabel ( label: titleLabel,
109+ containerView: containerView,
110+ insets: titleInsets,
111+ height: titleSize. height)
140112
141113 self . headerViewController. headerView. addSubview ( containerView)
142114
@@ -183,11 +155,13 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon
183155
184156 // MARK: MDCInkTouchControllerDelegate
185157
186- func inkTouchController( _ inkTouchController: MDCInkTouchController , shouldProcessInkTouchesAtTouchLocation location: CGPoint ) -> Bool {
158+ func inkTouchController( _ inkTouchController: MDCInkTouchController ,
159+ shouldProcessInkTouchesAtTouchLocation location: CGPoint ) -> Bool {
187160 return self . collectionView!. indexPathForItem ( at: location) != nil
188161 }
189162
190- func inkTouchController( _ inkTouchController: MDCInkTouchController , inkViewAtTouchLocation location: CGPoint ) -> MDCInkView {
163+ func inkTouchController( _ inkTouchController: MDCInkTouchController ,
164+ inkViewAtTouchLocation location: CGPoint ) -> MDCInkView {
191165 if let indexPath = self . collectionView!. indexPathForItem ( at: location) {
192166 let cell = self . collectionView!. cellForItem ( at: indexPath)
193167 return self . inkViewForView ( cell!)
@@ -197,9 +171,11 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon
197171
198172 // MARK: UICollectionViewDelegate
199173
200- override func collectionView( _ collectionView: UICollectionView , cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell {
201- let cell = collectionView. dequeueReusableCell ( withReuseIdentifier: " MDCCatalogCollectionViewCell " ,
202- for: indexPath)
174+ override func collectionView( _ collectionView: UICollectionView ,
175+ cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell {
176+ let cell =
177+ collectionView. dequeueReusableCell ( withReuseIdentifier: " MDCCatalogCollectionViewCell " ,
178+ for: indexPath)
203179 cell. backgroundColor = UIColor . white
204180
205181 let componentName = self . node. children [ indexPath. row] . title
@@ -213,7 +189,9 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon
213189 return cell
214190 }
215191
216- func collectionView( _ collectionView: UICollectionView , layout collectionViewLayout: UICollectionViewLayout , sizeForItemAtIndexPath indexPath: IndexPath ) -> CGSize {
192+ func collectionView( _ collectionView: UICollectionView ,
193+ layout collectionViewLayout: UICollectionViewLayout ,
194+ sizeForItemAtIndexPath indexPath: IndexPath ) -> CGSize {
217195 let pad = CGFloat ( 1 )
218196 var cellWidth = ( self . view. frame. size. width - 3 * pad) / 2
219197 if self . view. frame. size. width > self . view. frame. size. height {
@@ -234,6 +212,47 @@ class MDCCatalogComponentsController: UICollectionViewController, MDCInkTouchCon
234212 self . navigationController? . pushViewController ( vc, animated: true )
235213 }
236214
215+ // MARK: Private
216+ func constrainLabel( label: UILabel ,
217+ containerView: UIView ,
218+ insets: UIEdgeInsets ,
219+ height: CGFloat ) {
220+ _ = NSLayoutConstraint (
221+ item: label,
222+ attribute: . leading,
223+ relatedBy: . equal,
224+ toItem: containerView,
225+ attribute: . leading,
226+ multiplier: 1.0 ,
227+ constant: insets. left) . isActive = true
228+
229+ _ = NSLayoutConstraint (
230+ item: label,
231+ attribute: . trailing,
232+ relatedBy: . equal,
233+ toItem: containerView,
234+ attribute: . trailing,
235+ multiplier: 1.0 ,
236+ constant: 0 ) . isActive = true
237+
238+ _ = NSLayoutConstraint (
239+ item: label,
240+ attribute: . bottom,
241+ relatedBy: . equal,
242+ toItem: containerView,
243+ attribute: . bottom,
244+ multiplier: 1.0 ,
245+ constant: - insets. bottom) . isActive = true
246+
247+ _ = NSLayoutConstraint (
248+ item: label,
249+ attribute: . height,
250+ relatedBy: . equal,
251+ toItem: nil ,
252+ attribute: . notAnAttribute,
253+ multiplier: 1.0 ,
254+ constant: height) . isActive = true
255+ }
237256}
238257
239258// UIScrollViewDelegate
0 commit comments