Skip to content

Instantly share code, notes, and snippets.

@wspl
Created July 15, 2017 03:34
Show Gist options
  • Save wspl/40210b90512d0ef1ee4153d7faa98f1a to your computer and use it in GitHub Desktop.
Save wspl/40210b90512d0ef1ee4153d7faa98f1a to your computer and use it in GitHub Desktop.
v += tableView => { v in
v~.backgroundColor = .clear
v.top = v.prev.top - 5
v.bottom = v.parent.bottom
v.edgesX = v.parent.edgesX
v += self.refresher => { v in
v~.tintColor = .white
v~.addTarget(self, action: #selector(self.refresh), for: .valueChanged)
}
v~.tableHeaderView = (
v += UIViewWithRadius(frame: CGRect(x: 0, y: 0, width: 0, height: 100)) => { v in
v~.backgroundColor = .white
}
)~
v~.tableFooterView = (
v += self.loadMoreView => { v in
v += NVActivityIndicatorView(
frame: CGRect(x: 0, y: 0, width: 25, height: 25),
type: .ballPulse,
color: THEME_TEXT_LIGHT_COLOR
) => { v in
v.center = v.parent.center
v~.startAnimating()
}
}
)~
v~.tableFooterView = UIView()
v.onDidScroll { _ in
v~.bounces = v~.contentOffset.y <= 0
tableBg~.transform.ty = -v~.contentOffset.y > 0 ? -v~.contentOffset.y : 0
if !self.isLoading, v~.contentOffset.y + v~.frame.height > v~.tableFooterView!.frame.origin.y {
self.loadMore()
}
}
v.cell(model: self.data, component: PostCell.self)
}
class UIViewWithRadius: UIView {
override func layoutSubviews() {
super.layoutSubviews()
roundCorners([.topLeft, .topRight], radius: 5)
}
}
class UITableViewWithRadius: UITableView {
override func layoutSubviews() {
super.layoutSubviews()
roundCorners([.topLeft, .topRight], radius: 5)
}
func setFirstTopRadius() {
if let firstCell = cellForRow(at: IndexPath(row: 0, section: 0)) {
if !firstCell.hasRoundCorners() {
firstCell.roundCorners([.topLeft, .topRight], radius: 5)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment