// // UIScrollView+Empty.m // UIScrollViewEmpty // // Created by Jack on 2018/9/5. // Copyright © 2018年 United Software Applications. All rights reserved. // #import "UIScrollView+Empty.h" #import static const char *emptyKey = "emptyKey"; static const float duration = 0.25; @implementation UIScrollView (Empty) //- (void)setEmptyDataViewManualsize:(bool)bManualsize //{ // _emptyDataViewManualsize=bManualsize; //} - (void)setEmptyContentView:(RAEmptyDataView *)contentView { if (contentView) { UIView *view = objc_getAssociatedObject(self, emptyKey); if (view) { [view removeFromSuperview]; } [self insertSubview:contentView atIndex:0]; [self willChangeValueForKey:@"emptyView"]; objc_setAssociatedObject(self, emptyKey, contentView, OBJC_ASSOCIATION_RETAIN); [self didChangeValueForKey:@"emptyView"]; } } - (RAEmptyDataView *)emptyContentView { RAEmptyDataView *contentView = objc_getAssociatedObject(self, emptyKey); if (!contentView) { contentView = [RAEmptyDataView new]; contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; contentView.hidden = YES; [self setEmptyContentView:contentView]; } return contentView; } - (void)setEmptyView:(UIView *)emptyView { [self emptyContentView].emptyView = emptyView; } - (UIView *)emptyView { return [self emptyContentView].emptyView; } - (void)showEmpty { UIView *view = [self emptyContentView]; // view.alpha = 0.0f; view.hidden = NO; [self bringSubviewToFront:view]; // [UIView animateWithDuration:duration animations:^{ // view.alpha = 1.0f; // }]; } - (void)hideEmpty { UIView *view = [self emptyContentView]; // [UIView animateWithDuration:duration animations:^{ // view.alpha = 0.0f; // } completion:^(BOOL finished) { view.hidden = YES; // }]; [self sendSubviewToBack:view]; } - (void)setEmptyContentViewBackgroupColor:(UIColor *)color { self.emptyContentView.backgroundColor = color; } @end