Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ class CollectionViewExampleView: UIView {
self.houses = houses
collectionView.reloadData()
}

func viewOrientationDidChange() {
flowLayout.invalidateLayout()
}

override func layoutSubviews() {
super.layoutSubviews()
collectionView.pin.all()
collectionView.pin.all(pin.safeArea)
}
}

Expand All @@ -70,17 +74,7 @@ extension CollectionViewExampleView: UICollectionViewDelegateFlowLayout, UIColle
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let adjustedWidth = adjustWidthWithSafeArea(collectionView.bounds.width)

cellTemplate.configure(house: houses[indexPath.row])
return cellTemplate.sizeThatFits(CGSize(width: adjustedWidth, height: .greatestFiniteMagnitude))
}

private func adjustWidthWithSafeArea(_ width: CGFloat) -> CGFloat {
if #available(iOS 11.0, tvOS 11.0, *) {
return width - safeAreaInsets.left - safeAreaInsets.right
} else {
return width
}
return cellTemplate.sizeThatFits(CGSize(width: collectionView.bounds.width, height: .greatestFiniteMagnitude))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ class CollectionViewExampleViewController: UIViewController {
mainImageURL: URL(string: "https://i.pinimg.com/736x/6d/6c/ab/6d6cab9db70117727e3eb2adf0dbc080--small-modern-house-plans-modern-houses.jpg")!)
])
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
mainView.viewOrientationDidChange()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class HouseCell: UICollectionViewCell {
}

private func layout() {
headerView.pin.top().horizontally().height(100)
headerView.pin.top().horizontally(pin.safeArea).height(100)
nameLabel.pin.top().horizontally().margin(padding).sizeToFit(.width)

mainImage.pin.below(of: nameLabel).horizontally().height(300).marginTop(padding)
mainImage.pin.below(of: nameLabel).horizontally(pin.safeArea).height(300).marginTop(padding)

footerView.pin.below(of: mainImage).horizontally()
footerView.pin.below(of: mainImage).horizontally(pin.safeArea)
priceLabel.pin.top().horizontally().margin(6, padding).sizeToFit(.width)
distanceLabel.pin.top().after(of: priceLabel).right().margin(6, padding).sizeToFit(.width)
footerView.pin.height(max(priceLabel.frame.maxY, distanceLabel.frame.maxY) + 6)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MethodCell: UITableViewCell {
fileprivate func layout() {
iconImageView.pin.top().left().size(30).margin(padding)
nameLabel.pin.right(of: iconImageView, aligned: .center).right().marginHorizontal(padding).sizeToFit(.width)
descriptionLabel.pin.below(of: [iconImageView, nameLabel]).left().right().margin(padding).sizeToFit(.width)
descriptionLabel.pin.below(of: [iconImageView, nameLabel]).horizontally().margin(padding).sizeToFit(.width)
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ class MethodGroupHeader: UITableViewHeaderFooterView {
override func layoutSubviews() {
super.layoutSubviews()

titleLabel.pin.left().right().vCenter().margin(10).sizeToFit(.width)
titleLabel.pin.horizontally().vCenter().margin(10).sizeToFit(.width)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class TableViewExampleView: UIView {
super.init(frame: .zero)
backgroundColor = .white

tableView.estimatedRowHeight = 10
tableView.dataSource = self
tableView.delegate = self
tableView.tableFooterView = UIView()
Expand Down Expand Up @@ -79,8 +78,8 @@ extension TableViewExampleView: UITableViewDataSource, UITableViewDelegate {
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// The UITableView will call the cell's sizeThatFit() method to compute the height.
// WANRING: You must also set the UITableView.estimatedRowHeight for this to work.
return UITableViewAutomaticDimension
// Configure a MethodCell and ask its size.
methodCellTemplate.configure(method: methods[indexPath.row])
return methodCellTemplate.sizeThatFits(CGSize(width: tableView.bounds.width, height: .greatestFiniteMagnitude)).height
}
}
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- Nimble (7.0.3)
- PinLayout (1.5.9)
- PinLayout (1.6.0)
- Quick (1.2.0)
- Reveal-SDK (10)
- SwiftLint (0.25.0)
Expand All @@ -18,7 +18,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Nimble: 7f5a9c447a33002645a071bddafbfb24ea70e0ac
PinLayout: b2ebf8622b28e82b6e1216ab4e4a0a8d082214fe
PinLayout: a2bbe9057d49a1e326b13dc4fe8c14751f8c8844
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
Reveal-SDK: 7869ddf1f902cabbb07a1f0dd06bd25861a126f7
SwiftLint: e14651157288e9e01d6e1a71db7014fb5744a8ea
Expand Down