zoukankan      html  css  js  c++  java
  • iOS全局调用的提示 没有网络 没有更多 等。。 短时间内自动消失

    本来想用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 = @"你想要的东西";

  • 相关阅读:
    DExpose2:Windows 下窗体平铺预览
    第二章 随机变量及其分布3
    资源文件分享到QQ群共享里的方法
    第三章 多维随机变量及其分布1
    RegexBuddy
    第四章 随机变量的数字特征3
    html 表格排序
    关于微软自带的身份和角色验证
    学习中小型软件开发步骤
    学习路线图
  • 原文地址:https://www.cnblogs.com/weijie-1/p/5472029.html
Copyright © 2011-2022 走看看