zoukankan      html  css  js  c++  java
  • 提示信息View自动收回

    #import <UIKit/UIKit.h>
    
    @interface NotifyView : UIView
    /*  param 1 父view  param2  将要用来提示的内容  */
    +(void)showNotifyInSuperView:(UIView *)superView context:(NSString *)aString;
    
    @end
    //
    //  NotifyView.m
    //  NotifyViewText
    //
    //  Created by admin on 16/1/15.
    //  Copyright © 2016年 123. All rights reserved.
    //
    
    #import "NotifyView.h"
    
    @implementation NotifyView
    +(void)showNotifyInSuperView:(UIView *)superView context:(NSString *)aString
    {
        NotifyView *ntfv = (NotifyView *)[superView viewWithTag:12345];
        if (!ntfv)
        {
            ntfv = [[NotifyView alloc]initWithFrame:CGRectMake(0, 0, 280, 120)];
            ntfv.center = superView.center;
            ntfv.tag = 12345;
            ntfv.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
            ntfv.layer.cornerRadius = 12.0f;
            ntfv.clipsToBounds = YES;
            ntfv.layer.masksToBounds = YES;
            [superView addSubview:ntfv];
            
            UILabel *label  = [UILabel new];
            label.frame = CGRectMake(8, 8, ntfv.bounds.size.width - 16, ntfv.bounds.size.height - 16);
            label.text = aString;
            label.textAlignment = NSTextAlignmentCenter;
            label.textColor = [UIColor whiteColor];
            label.numberOfLines = 3;
            label.lineBreakMode = NSLineBreakByWordWrapping;
            label.backgroundColor = [UIColor clearColor];
            [ntfv addSubview:label];
    
        }else
        {
           ntfv.alpha = 0.9;
        }
        [UIView animateWithDuration:1.0 animations:^{
            [ntfv.superview bringSubviewToFront:ntfv];
        }];
        [NSTimer scheduledTimerWithTimeInterval:2.0f target:ntfv selector:@selector(timerFired:) userInfo:@{@"view":ntfv} repeats:NO];
    }
    -(void)timerFired:(NSTimer *)sender
    {
        NotifyView *ntfv = sender.userInfo[@"view"];
        [UIView animateWithDuration:1.0 animations:^{
            [ntfv.superview sendSubviewToBack:ntfv];
            ntfv.alpha = 0.0;
            [sender invalidate];
        }];
    }
    @end

    调用方式

    1.导入头文件

    #import "NotifyView.h"

    2.通过类提供的接口调用----(输入需要展示的参数内容!!!)

    - (IBAction)showNotify:(UIButton *)sender
    {
        [NotifyView showNotifyInSuperView:self.view context:@"微卡京东方货架上的高房价华盛顿号开发商的积分卡水电费水电费更好的房价考核和哪个部分"];
    }
  • 相关阅读:
    [转载]WSUS客户端排错--使用wsus client tools
    [转载]vSphere ESXi主机配置iSCSI存储
    RHEL6.5下oracle11G的监听启动停止
    配置EM遇到的问题:*_orcl not foundlistener not upError creating the repository
    chrome有道翻译--书签栏关闭开启快捷键
    linux下sqlplus实现浏览历史命令和删除错误字母功能
    windows下plsql安装并配置oracle client
    chrome google浏览器添加AdBlock插件
    Python基础之异常处理
    Python基础之finally异常处理
  • 原文地址:https://www.cnblogs.com/Mgs1991/p/5138894.html
Copyright © 2011-2022 走看看