Skip to content

Commit

Permalink
support multiple vertical spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hongxinhope committed Apr 7, 2016
1 parent 4f683ba commit d0c9d09
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Example/EmptyDataDemoTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ class EmptyDataDemoTableViewController: UITableViewController, TBEmptyDataSetDat
return 0
}

func verticalSpacesForEmptyDataSet(scrollView: UIScrollView!) -> [CGFloat] {
return [25, 8]
}

func customViewForEmptyDataSet(scrollView: UIScrollView!) -> UIView? {
if isLoading {
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
Expand Down
4 changes: 2 additions & 2 deletions Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.5</string>
<string>1.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>6</string>
<string>7</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func verticalOffsetForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat {
// return the vertical offset for EmptyDataSet, default is 0
}

func verticalSpaceForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat {
// return the vertical space for EmptyDataSet, default is 12
func verticalSpacesForEmptyDataSet(scrollView: UIScrollView!) -> [CGFloat] {
// return the vertical spaces from top to bottom for EmptyDataSet, default is [12, 12]
}

func customViewForEmptyDataSet(scrollView: UIScrollView!) -> UIView? {
Expand Down
2 changes: 1 addition & 1 deletion TBEmptyDataSet.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "TBEmptyDataSet"
s.version = "1.5"
s.version = "1.6"
s.summary = "An extension of UITableView/UICollectionView's super class, it will display a placeholder when the data is empty."

s.homepage = "https://github.com/teambition/TBEmptyDataSet"
Expand Down
5 changes: 3 additions & 2 deletions TBEmptyDataSet/EmptyDataView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class EmptyDataView: UIView {
}

var verticalOffset: CGFloat!
var verticalSpace: CGFloat!
var verticalSpaces: [CGFloat]!

// MARK: - Helper
private func removeAllConstraints() {
Expand Down Expand Up @@ -172,7 +172,8 @@ class EmptyDataView: UIView {
for (index, viewString) in viewStrings.enumerate() {
verticalFormat += "[\(viewString)]"
if index != viewStrings.count - 1 {
verticalFormat += "-\(verticalSpace)-"
let verticalSpace = index < verticalSpaces.count ? verticalSpaces[index] : DefaultValues.verticalSpace
verticalFormat += "-(\(verticalSpace))-"
}
}

Expand Down
4 changes: 2 additions & 2 deletions TBEmptyDataSet/ProtocolExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public extension TBEmptyDataSetDataSource {
return DefaultValues.verticalOffset
}

func verticalSpaceForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat {
return DefaultValues.verticalSpace
func verticalSpacesForEmptyDataSet(scrollView: UIScrollView!) -> [CGFloat] {
return [DefaultValues.verticalSpace, DefaultValues.verticalSpace]
}

func customViewForEmptyDataSet(scrollView: UIScrollView!) -> UIView? {
Expand Down
2 changes: 1 addition & 1 deletion TBEmptyDataSet/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.5</string>
<string>1.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
8 changes: 4 additions & 4 deletions TBEmptyDataSet/TBEmptyDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public protocol TBEmptyDataSetDataSource: NSObjectProtocol {
func backgroundColorForEmptyDataSet(scrollView: UIScrollView!) -> UIColor?

func verticalOffsetForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat
func verticalSpaceForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat
func verticalSpacesForEmptyDataSet(scrollView: UIScrollView!) -> [CGFloat]

func customViewForEmptyDataSet(scrollView: UIScrollView!) -> UIView?
}
Expand Down Expand Up @@ -124,8 +124,8 @@ extension UIScrollView: UIGestureRecognizerDelegate {
return emptyDataSetDataSource?.verticalOffsetForEmptyDataSet(self) ?? DefaultValues.verticalOffset
}

private func emptyDataSetVerticalSpace() -> CGFloat {
return emptyDataSetDataSource?.verticalSpaceForEmptyDataSet(self) ?? DefaultValues.verticalSpace
private func emptyDataSetVerticalSpaces() -> [CGFloat] {
return emptyDataSetDataSource?.verticalSpacesForEmptyDataSet(self) ?? [DefaultValues.verticalSpace, DefaultValues.verticalSpace]
}

private func emptyDataSetCustomView() -> UIView? {
Expand Down Expand Up @@ -252,7 +252,7 @@ extension UIScrollView: UIGestureRecognizerDelegate {
emptyDataView.resetEmptyDataView()

emptyDataView!.verticalOffset = emptyDataSetVerticalOffset()
emptyDataView!.verticalSpace = emptyDataSetVerticalSpace()
emptyDataView!.verticalSpaces = emptyDataSetVerticalSpaces()

if let customView = emptyDataSetCustomView() {
emptyDataView.customView = customView
Expand Down

0 comments on commit d0c9d09

Please sign in to comment.