Skip to content
This repository was archived by the owner on Nov 29, 2022. It is now read-only.
Open
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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Please read this very interesting article about [*Designing For The Empty States
* Gives multiple possibilities of layout and appearance, by showing an image and/or title label and/or description label and/or button.
* Uses NSAttributedString for easier appearance customisation.
* Uses auto-layout to automagically center the content to the tableview, with auto-rotation support. Also accepts custom vertical and horizontal alignment.
* Background color customisation.
* Background color customisation, including gradient.
* Allows tap gesture on the whole tableview rectangle (useful for resigning first responder or similar actions).
* For more advanced customisation, it allows a custom view.
* Compatible with Storyboard.
Expand Down Expand Up @@ -157,6 +157,16 @@ The background color for the empty state:
}
```

The background gradient for the empty state:
```objc
- (CAGradientLayer *)backgroundGradientForEmptyDataSet:(UIScrollView *)scrollView
{
CAGradientLayer *backgroundGradient = [CAGradientLayer layer];
backgroundGradient.colors = @[(id)[[UIColor whiteColor] CGColor], (id)[[UIColor blackColor] CGColor]];
return backgroundGradient;
}
```

If you need a more complex layout, you can return a custom view instead:
```objc
- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
Expand Down
10 changes: 10 additions & 0 deletions Source/UIScrollView+EmptyDataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@
*/
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView;


/**
Asks the data source for the background gradient of the dataset. Default is none.

@param scrollView A scrollView subclass object informing the data source.
@return A gradient to be applied to the dataset background view.
*/
- (CAGradientLayer *)backgroundGradientForEmptyDataSet:(UIScrollView *)scrollView;


/**
Asks the data source for a custom view to be displayed instead of the default views such as labels, imageview and button. Default is nil.
Use this method to show an activity view indicator for loading feedback, or for complete custom empty data set.
Expand Down
11 changes: 11 additions & 0 deletions Source/UIScrollView+EmptyDataSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ - (UIColor *)dzn_dataSetBackgroundColor
return [UIColor clearColor];
}

- (void)dzn_dataSetBackgroundGradient
{
if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(backgroundGradientForEmptyDataSet:)]) {
CAGradientLayer *gradient = [self.emptyDataSetSource backgroundGradientForEmptyDataSet:self];
if (gradient) NSAssert([gradient isKindOfClass:[CAGradientLayer class]], @"You must return a valid CAGradientLayer object for -backgroundGradientForEmptyDataSet:");
gradient.frame = self.bounds;
[self.layer insertSublayer:gradient atIndex:0];
}
}

- (UIView *)dzn_customView
{
if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(customViewForEmptyDataSet:)]) {
Expand Down Expand Up @@ -521,6 +531,7 @@ - (void)dzn_reloadEmptyDataSet

// Configure the empty dataset view
view.backgroundColor = [self dzn_dataSetBackgroundColor];
[self dzn_dataSetBackgroundGradient]
view.hidden = NO;
view.clipsToBounds = YES;

Expand Down