//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;
}
网友评论