| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // RAEmptyDataView.m
- // UIScrollViewEmpty
- //
- // Created by Jack on 2018/9/5.
- // Copyright © 2018年 United Software Applications. All rights reserved.
- //
- #import "RAEmptyDataView.h"
- @implementation RAEmptyDataView
- #pragma mark - Initial
- - (instancetype)init {
- if (self = [super init]) {
- self.backgroundColor = [UIColor clearColor];
- // self.translatesAutoresizingMaskIntoConstraints = NO;
- }
- return self;
- }
- - (void)setFrame:(CGRect)frame {
- [super setFrame:frame];
- }
- - (void)didMoveToSuperview {
- [super didMoveToSuperview];
- self.frame = self.superview.bounds;
- }
- - (void)willMoveToSuperview:(UIView *)newSuperview {
- [super willMoveToSuperview:newSuperview];
- }
- - (void)setHidden:(BOOL)hidden {
- [super setHidden:hidden];
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
-
- if (self.emptyView) {
-
- CGFloat w = self.bounds.size.width;
- CGFloat h = self.bounds.size.height;
- CGFloat emptyW = self.emptyView.bounds.size.width;
- CGFloat emptyH = self.emptyView.bounds.size.height;
-
- CGFloat x = (w - emptyW) * 0.5;
- CGFloat y = (h - emptyH) * 0.5;
- self.emptyView.frame = CGRectMake(x, y, emptyW, emptyH);
- }
- }
- - (void)clear {
- NSArray *subviews = self.subviews;
- if (subviews && subviews.count > 0) {
- for (UIView *subview in subviews) {
- [subview removeFromSuperview];
- }
- }
- }
- - (void)setEmptyView:(UIView *)emptyView {
- _emptyView = emptyView;
-
- [self clear];
- [self addSubview:_emptyView];
- // NSLayoutConstraint *enterX = [NSLayoutConstraint constraintWithItem:_emptyView
- // attribute:NSLayoutAttributeCenterX
- // relatedBy:NSLayoutRelationEqual
- // toItem:self
- // attribute:NSLayoutAttributeCenterX
- // multiplier:1
- // constant:0];
- //
- // NSLayoutConstraint *enterY = [NSLayoutConstraint constraintWithItem:_emptyView
- // attribute:NSLayoutAttributeCenterY
- // relatedBy:NSLayoutRelationEqual
- // toItem:self
- // attribute:NSLayoutAttributeCenterY
- // multiplier:1
- // constant:0];
- //
- // NSLayoutConstraint *w = [NSLayoutConstraint constraintWithItem:_emptyView
- // attribute:NSLayoutAttributeWidth
- // relatedBy:NSLayoutRelationEqual
- // toItem:nil
- // attribute:NSLayoutAttributeNotAnAttribute
- // multiplier:1
- // constant:100];
- //
- // NSLayoutConstraint *h = [NSLayoutConstraint constraintWithItem:_emptyView
- // attribute:NSLayoutAttributeHeight
- // relatedBy:NSLayoutRelationEqual
- // toItem:nil
- // attribute:NSLayoutAttributeNotAnAttribute
- // multiplier:1
- // constant:70];
- //
- //
- // [self addConstraints:@[enterX,enterY,w,h]];
- }
- @end
|