美文网首页
ios无数据展示

ios无数据展示

作者: 易小林_2049 | 来源:发表于2019-02-27 10:31 被阅读0次

//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;

}

相关文章

网友评论

      本文标题:ios无数据展示

      本文链接:https://www.haomeiwen.com/subject/nyjxuqtx.html