本来想用SVProgressHUD 但是由于这个需求相对要简单 所以自己写了
下面上代码
.h 文件
#import <UIKit/UIKit.h>
@interface HaveNoMore : UIView
+ (instancetype)sharedHaveNoMoreView;
@property (nonatomic,strong)UILabel *textLabel;
- (void)show;
@end
.m 文件
#import "HaveNoMore.h"
@implementation HaveNoMore
#pragma mark - 单例
+ (instancetype)sharedHaveNoMoreView {
static HaveNoMore *noMoreView;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
noMoreView = [[HaveNoMore alloc] init];
});
return noMoreView;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setupUI];
}
return self;
}
- (void)setupUI {
self.alpha = 0;
self.backgroundColor = [UIColor colorWithWJString:@"000000" alpha:0.8];
UILabel *label = [[UILabel alloc] init];
label.text = @"没有更多";
label.textColor = [UIColor whiteColor];
label.font = [UIFont systemFontOfSize:15 * bbtFitH];
self.textLabel = label;
[self addSubview:self.textLabel];
self.frame = CGRectMake(kDeviceWidth * 0.5 - (125 * 0.5) * bbtFitH, 283 * bbtFitH, 125 * bbtFitH, 50 * bbtFitH);
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self);
}];
self.layer.cornerRadius = 5;
self.layer.masksToBounds = YES;
[[UIApplication sharedApplication].keyWindow addSubview:self];
}
- (void)show {
self.alpha = 1;
[UIView animateWithDuration:1 animations:^{
self.alpha = 0;
}];
}
由于是加到了 keyWindow 上 所以不需要在页面添加 将头文件导入在 pch 文件内 使用的时候只需要调用 [[HaveNoMore sharedHaveNoMoreView] show]就可以了
更改文字可以这样 [HaveNoMore sharedHaveNoMoreView].textLabel.text = @"你想要的东西";