From 48672978d53771495f0151bb2fd7454e19cbfc16 Mon Sep 17 00:00:00 2001 From: Roaflin Date: Tue, 18 Oct 2016 10:44:26 +0200 Subject: [PATCH 1/3] Adds customisation for button: corner radius, border color, border width --- Source/UIScrollView+EmptyDataSet.h | 51 +++++++++++++++++++++--------- Source/UIScrollView+EmptyDataSet.m | 33 +++++++++++++++++++ 2 files changed, 69 insertions(+), 15 deletions(-) diff --git a/Source/UIScrollView+EmptyDataSet.h b/Source/UIScrollView+EmptyDataSet.h index ddd45aa3..7245975c 100644 --- a/Source/UIScrollView+EmptyDataSet.h +++ b/Source/UIScrollView+EmptyDataSet.h @@ -10,8 +10,6 @@ #import -NS_ASSUME_NONNULL_BEGIN - @protocol DZNEmptyDataSetSource; @protocol DZNEmptyDataSetDelegate; @@ -24,9 +22,9 @@ NS_ASSUME_NONNULL_BEGIN @interface UIScrollView (EmptyDataSet) /** The empty datasets data source. */ -@property (nonatomic, weak, nullable) IBOutlet id emptyDataSetSource; +@property (nonatomic, weak) IBOutlet id emptyDataSetSource; /** The empty datasets delegate. */ -@property (nonatomic, weak, nullable) IBOutlet id emptyDataSetDelegate; +@property (nonatomic, weak) IBOutlet id emptyDataSetDelegate; /** YES if any empty dataset is visible. */ @property (nonatomic, readonly, getter = isEmptyDataSetVisible) BOOL emptyDataSetVisible; @@ -53,7 +51,7 @@ NS_ASSUME_NONNULL_BEGIN @param scrollView A scrollView subclass informing the data source. @return An attributed string for the dataset title, combining font, text color, text pararaph style, etc. */ -- (nullable NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView; +- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView; /** Asks the data source for the description of the dataset. @@ -62,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN @param scrollView A scrollView subclass informing the data source. @return An attributed string for the dataset description text, combining font, text color, text pararaph style, etc. */ -- (nullable NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView; +- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView; /** Asks the data source for the image of the dataset. @@ -70,7 +68,7 @@ NS_ASSUME_NONNULL_BEGIN @param scrollView A scrollView subclass informing the data source. @return An image for the dataset. */ -- (nullable UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView; +- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView; /** @@ -79,7 +77,7 @@ NS_ASSUME_NONNULL_BEGIN @param scrollView A scrollView subclass object informing the data source. @return A color to tint the image of the dataset. */ -- (nullable UIColor *)imageTintColorForEmptyDataSet:(UIScrollView *)scrollView; +- (UIColor *)imageTintColorForEmptyDataSet:(UIScrollView *)scrollView; /** * Asks the data source for the image animation of the dataset. @@ -88,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN * * @return image animation */ -- (nullable CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView; +- (CAAnimation *) imageAnimationForEmptyDataSet:(UIScrollView *) scrollView; /** Asks the data source for the title to be used for the specified button state. @@ -98,7 +96,7 @@ NS_ASSUME_NONNULL_BEGIN @param state The state that uses the specified title. The possible values are described in UIControlState. @return An attributed string for the dataset button title, combining font, text color, text pararaph style, etc. */ -- (nullable NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; +- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; /** Asks the data source for the image to be used for the specified button state. @@ -108,7 +106,7 @@ NS_ASSUME_NONNULL_BEGIN @param state The state that uses the specified title. The possible values are described in UIControlState. @return An image for the dataset button imageview. */ -- (nullable UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; +- (UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; /** Asks the data source for a background image to be used for the specified button state. @@ -118,7 +116,7 @@ NS_ASSUME_NONNULL_BEGIN @param state The state that uses the specified image. The values are described in UIControlState. @return An attributed string for the dataset button title, combining font, text color, text pararaph style, etc. */ -- (nullable UIImage *)buttonBackgroundImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; +- (UIImage *)buttonBackgroundImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; /** Asks the data source for the background color of the dataset. Default is clear color. @@ -126,7 +124,7 @@ NS_ASSUME_NONNULL_BEGIN @param scrollView A scrollView subclass object informing the data source. @return A color to be applied to the dataset background view. */ -- (nullable UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView; +- (UIColor *)backgroundColorForEmptyDataSet:(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. @@ -136,7 +134,7 @@ NS_ASSUME_NONNULL_BEGIN @param scrollView A scrollView subclass object informing the delegate. @return The custom view. */ -- (nullable UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView; +- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView; /** Asks the data source for a offset for vertical and horizontal alignment of the content. Default is CGPointZero. @@ -155,6 +153,30 @@ NS_ASSUME_NONNULL_BEGIN */ - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView; +/** + Asks the data source for the button's border width. Default is 0. + + @param scrollView A scrollView subclass object informing the delegate. + @return The button's border width. + */ +- (CGFloat)buttonBorderWidthForEmptyDataSet:(UIScrollView *)scrollView; + +/** + Asks the data source for the color of the border. Default is clear. + + @param scrollView A scrollView subclass object informing the delegate. + @return The button's border color. + */ +- (CGColorRef)buttonBorderColorForEmptyDataSet:(UIScrollView *)scrollView; + +/** + Asks the data source for the corner radius of the button. Default is 0. + + @param scrollView A scrollView subclass object informing the delegate. + @return The button's corner radius. + */ +- (CGFloat)buttonBorderCornerRadiusForEmptyDataSet:(UIScrollView *)scrollView; + @end @@ -280,4 +302,3 @@ NS_ASSUME_NONNULL_BEGIN #undef DZNEmptyDataSetDeprecated -NS_ASSUME_NONNULL_END diff --git a/Source/UIScrollView+EmptyDataSet.m b/Source/UIScrollView+EmptyDataSet.m index ce43ffcd..5ddbb8d9 100644 --- a/Source/UIScrollView+EmptyDataSet.m +++ b/Source/UIScrollView+EmptyDataSet.m @@ -245,6 +245,33 @@ - (UIImage *)dzn_buttonBackgroundImageForState:(UIControlState)state return nil; } +- (CGFloat)dzn_buttonBorderWidth { + CGFloat width = 0.0; + + if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(buttonBorderWidthForEmptyDataSet:)]) + width = [self.emptyDataSetSource buttonBorderWidthForEmptyDataSet:self]; + + return width; +} + +- (CGColorRef)dzn_buttonBorderColor { + CGColorRef color = [UIColor clearColor].CGColor; + + if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(buttonBorderColorForEmptyDataSet:)]) + color = [self.emptyDataSetSource buttonBorderColorForEmptyDataSet:self]; + + return color; +} + +- (CGFloat)dzn_buttonCornerRadius { + CGFloat radius = 0.0; + + if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(buttonBorderCornerRadiusForEmptyDataSet:)]) + radius = [self.emptyDataSetSource buttonBorderCornerRadiusForEmptyDataSet:self]; + + return radius; +} + - (UIColor *)dzn_dataSetBackgroundColor { if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(backgroundColorForEmptyDataSet:)]) { @@ -513,6 +540,12 @@ - (void)dzn_reloadEmptyDataSet [view.button setAttributedTitle:[self dzn_buttonTitleForState:UIControlStateHighlighted] forState:UIControlStateHighlighted]; [view.button setBackgroundImage:[self dzn_buttonBackgroundImageForState:UIControlStateNormal] forState:UIControlStateNormal]; [view.button setBackgroundImage:[self dzn_buttonBackgroundImageForState:UIControlStateHighlighted] forState:UIControlStateHighlighted]; + + view.button.layer.masksToBounds = YES; + view.button.layer.borderWidth = [self dzn_buttonBorderWidth]; + view.button.layer.borderColor = [self dzn_buttonBorderColor]; + view.button.layer.cornerRadius = [self dzn_buttonCornerRadius]; + view.button.tintColor = [UIColor colorWithCGColor:[self dzn_buttonBorderColor]]; } } From e3363b9f9595bfbc9e0271a5e52c53de57976e9c Mon Sep 17 00:00:00 2001 From: Roaflin Date: Tue, 18 Oct 2016 10:52:07 +0200 Subject: [PATCH 2/3] Puts back nullable and non null for properties and methods --- Source/UIScrollView+EmptyDataSet.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/Source/UIScrollView+EmptyDataSet.h b/Source/UIScrollView+EmptyDataSet.h index 7245975c..8b4b05f6 100644 --- a/Source/UIScrollView+EmptyDataSet.h +++ b/Source/UIScrollView+EmptyDataSet.h @@ -10,6 +10,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + @protocol DZNEmptyDataSetSource; @protocol DZNEmptyDataSetDelegate; @@ -22,9 +24,9 @@ @interface UIScrollView (EmptyDataSet) /** The empty datasets data source. */ -@property (nonatomic, weak) IBOutlet id emptyDataSetSource; +@property (nonatomic, weak, nullable) IBOutlet id emptyDataSetSource; /** The empty datasets delegate. */ -@property (nonatomic, weak) IBOutlet id emptyDataSetDelegate; +@property (nonatomic, weak, nullable) IBOutlet id emptyDataSetDelegate; /** YES if any empty dataset is visible. */ @property (nonatomic, readonly, getter = isEmptyDataSetVisible) BOOL emptyDataSetVisible; @@ -51,7 +53,7 @@ @param scrollView A scrollView subclass informing the data source. @return An attributed string for the dataset title, combining font, text color, text pararaph style, etc. */ -- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView; +- (nullable NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView; /** Asks the data source for the description of the dataset. @@ -60,7 +62,7 @@ @param scrollView A scrollView subclass informing the data source. @return An attributed string for the dataset description text, combining font, text color, text pararaph style, etc. */ -- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView; +- (nullable NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView; /** Asks the data source for the image of the dataset. @@ -68,7 +70,7 @@ @param scrollView A scrollView subclass informing the data source. @return An image for the dataset. */ -- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView; +- (nullable UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView; /** @@ -77,7 +79,7 @@ @param scrollView A scrollView subclass object informing the data source. @return A color to tint the image of the dataset. */ -- (UIColor *)imageTintColorForEmptyDataSet:(UIScrollView *)scrollView; +- (nullable UIColor *)imageTintColorForEmptyDataSet:(UIScrollView *)scrollView; /** * Asks the data source for the image animation of the dataset. @@ -86,7 +88,7 @@ * * @return image animation */ -- (CAAnimation *) imageAnimationForEmptyDataSet:(UIScrollView *) scrollView; +- (nullable CAAnimation *) imageAnimationForEmptyDataSet:(UIScrollView *) scrollView; /** Asks the data source for the title to be used for the specified button state. @@ -96,7 +98,7 @@ @param state The state that uses the specified title. The possible values are described in UIControlState. @return An attributed string for the dataset button title, combining font, text color, text pararaph style, etc. */ -- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; +- (nullable NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; /** Asks the data source for the image to be used for the specified button state. @@ -106,7 +108,7 @@ @param state The state that uses the specified title. The possible values are described in UIControlState. @return An image for the dataset button imageview. */ -- (UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; +- (nullable UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; /** Asks the data source for a background image to be used for the specified button state. @@ -116,7 +118,7 @@ @param state The state that uses the specified image. The values are described in UIControlState. @return An attributed string for the dataset button title, combining font, text color, text pararaph style, etc. */ -- (UIImage *)buttonBackgroundImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; +- (nullable UIImage *)buttonBackgroundImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state; /** Asks the data source for the background color of the dataset. Default is clear color. @@ -124,7 +126,7 @@ @param scrollView A scrollView subclass object informing the data source. @return A color to be applied to the dataset background view. */ -- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView; +- (nullable UIColor *)backgroundColorForEmptyDataSet:(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. @@ -134,7 +136,7 @@ @param scrollView A scrollView subclass object informing the delegate. @return The custom view. */ -- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView; +- (nullable UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView; /** Asks the data source for a offset for vertical and horizontal alignment of the content. Default is CGPointZero. @@ -302,3 +304,5 @@ #undef DZNEmptyDataSetDeprecated +NS_ASSUME_NONNULL_END + From 72400881a53a32e7a72ea0c8bc2bcbdae924b9d5 Mon Sep 17 00:00:00 2001 From: Bilal Benlarbi Date: Mon, 24 Oct 2016 14:30:51 +0200 Subject: [PATCH 3/3] button width fixed for border --- Source/UIScrollView+EmptyDataSet.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Source/UIScrollView+EmptyDataSet.m b/Source/UIScrollView+EmptyDataSet.m index 5ddbb8d9..6b8fb166 100644 --- a/Source/UIScrollView+EmptyDataSet.m +++ b/Source/UIScrollView+EmptyDataSet.m @@ -542,6 +542,24 @@ - (void)dzn_reloadEmptyDataSet [view.button setBackgroundImage:[self dzn_buttonBackgroundImageForState:UIControlStateHighlighted] forState:UIControlStateHighlighted]; view.button.layer.masksToBounds = YES; + [view.button sizeToFit]; + + [view.button addConstraint:[NSLayoutConstraint constraintWithItem:view.button + attribute:NSLayoutAttributeWidth + relatedBy:NSLayoutRelationEqual + toItem:nil + attribute:NSLayoutAttributeNotAnAttribute + multiplier:1 + constant:view.button.frame.size.width + 60]]; + + [view.contentView addConstraint:[NSLayoutConstraint constraintWithItem:view.button + attribute:NSLayoutAttributeCenterX + relatedBy:NSLayoutRelationEqual + toItem:view.contentView + attribute:NSLayoutAttributeCenterX + multiplier:1 + constant:0]]; + view.button.layer.borderWidth = [self dzn_buttonBorderWidth]; view.button.layer.borderColor = [self dzn_buttonBorderColor]; view.button.layer.cornerRadius = [self dzn_buttonCornerRadius];