Skip to content

Commit c38f637

Browse files
author
Luc Dion
committed
Update sample
1 parent 1dd4858 commit c38f637

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

Example/FlexLayoutSample/UI/Examples/RaywenderlichTutorial/RaywenderlichTutorialView.swift

+19-20
Original file line numberDiff line numberDiff line change
@@ -189,39 +189,38 @@ class RayWenderlichTutorialView: BaseView {
189189
}
190190

191191
fileprivate func showActionViewFor(imageName: String, text: String) -> UIView {
192-
let actionView = UIView(frame: .zero)
193-
actionView.flex.alignItems(.center).width(50).marginRight(20.0)
194-
195-
let actionButton = UIButton(type: .custom)
196-
actionButton.setImage(UIImage(named: imageName), for: .normal)
197-
actionButton.flex.padding(10)
198-
actionView.addSubview(actionButton)
192+
let actionView = UIView()
199193

200-
let actionLabel = showLabelFor(text: text)
201-
actionView.addSubview(actionLabel)
194+
actionView.flex.alignItems(.center).width(50).marginRight(20.0).define { (flex) in
195+
let actionButton = UIButton(type: .custom)
196+
actionButton.setImage(UIImage(named: imageName), for: .normal)
197+
flex.addItem(actionButton).padding(10)
198+
199+
let actionLabel = showLabelFor(text: text)
200+
flex.addItem(actionLabel)
201+
}
202202

203203
return actionView
204204
}
205205

206206
fileprivate func showTabBarFor(text: String, selected: Bool) -> UIView {
207-
let tabView = UIView(frame: .zero)
208-
tabView.flex.alignItems(.center).marginRight(20)
209-
210207
let tabLabelFont = selected ? UIFont.boldSystemFont(ofSize: 14.0) : UIFont.systemFont(ofSize: 14.0)
211208

212209
#if swift(>=4)
213-
let fontSize = text.size(withAttributes: [NSAttributedStringKey.font: tabLabelFont])
210+
let labelSize = text.size(withAttributes: [NSAttributedStringKey.font: tabLabelFont])
214211
#else
215-
let fontSize = text.size(attributes: [NSFontAttributeName: tabLabelFont])
212+
let labelSize = text.size(attributes: [NSFontAttributeName: tabLabelFont])
216213
#endif
217214

218-
let tabSelectionView = UIView(frame: CGRect(x: 0, y: 0, width: fontSize.width, height: 3))
219-
tabSelectionView.flex.width(fontSize.width).marginBottom(5)
220-
tabSelectionView.backgroundColor = selected ? .red : .clear
221-
tabView.addSubview(tabSelectionView)
215+
let tabView = UIView()
222216

223-
let tabLabel = showLabelFor(text: text, font: tabLabelFont)
224-
tabView.addSubview(tabLabel)
217+
tabView.flex.alignItems(.center).marginRight(20).define { (flex) in
218+
let tabSelectionView = UIView()
219+
flex.addItem(tabSelectionView).width(labelSize.width).height(3).marginBottom(5).backgroundColor(selected ? .red : .clear)
220+
221+
let tabLabel = showLabelFor(text: text, font: tabLabelFont)
222+
flex.addItem(tabLabel)
223+
}
225224

226225
return tabView
227226
}

0 commit comments

Comments
 (0)