ios无数据展示

//NoDataView.h

#import

@interfaceNoDataView :UIView

@property (weak, nonatomic) UIView *contentView;

@property (weak, nonatomic) UIImageView *noDataIv;

@property (weak, nonatomic) UILabel *noDataLabel;

@end


//  NoDataView.m

#import "NoDataView.h"

@implementation NoDataView

- (instancetype) initWithFrame:(CGRect)frame {

    if (self= [super initWithFrame:frame])  {

        self.backgroundColor = [UIColor clearColor];

        [self initUI];

    }

    return self;

}

- (void) initUI {

    [_noDataIv removeFromSuperview];

    [_noDataLabel removeFromSuperview];

    [_contentView removeFromSuperview];


    UIView *noDataView = [[UIView alloc] init];

    noDataView.frame = self.bounds;

    noDataView.backgroundColor = [UIColor whiteColor];

    self.contentView = noDataView;

    [self addSubview:noDataView];


    UIImage *noData = [UIImage imageNamed:@"no_record"];

    UIImageView *noDataImage = [[UIImageView alloc] initWithImage:noData];

    [noDataView addSubview:noDataImage];

    noDataImage.frame = CGRectMake(0, (self.height - noData.size.height-kSize(18) -20)/2.0, kScreenW, noData.size.height);

    //noDataImage.hidden = YES;

    noDataImage.contentMode = UIViewContentModeCenter;

    self.noDataIv= noDataImage;


    UILabel *noDataLabel = [UILabel new];

    [noDataView addSubview:noDataLabel];

    noDataLabel.frame = CGRectMake(0,  noDataImage.bottom + kSize(18), kScreenW, 20);

    //noDataLabel.hidden = YES;

    noDataLabel.text = @"暂无数据";

    noDataLabel.textColor = TEXTCOLOR;

    noDataLabel.font = MEDIUMFONT;

    noDataLabel.textAlignment = NSTextAlignmentCenter;


    self.noDataLabel= noDataLabel;

}

@end


//使用

- (void) showTotalPowerNoDataView:(NSString*)text {

    _totalPowerView.hidden = YES;

    if  (_totalPowerNoDataView == nil)  {

        _totalPowerNoDataView = [[NoDataView alloc] initWithFrame:_totalPowerView.frame];

        [_contentView addSubview:_totalPowerNoDataView];

    }

    _totalPowerNoDataView.noDataLabel.text = text;

    _totalPowerNoDataView.hidden = NO;

}

- (void) hideTotalPowerNoDataView {

    _totalPowerView.hidden = NO;

    _totalPowerNoDataView.hidden = YES;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容