zoukankan      html  css  js  c++  java
  • 自定义写一个提示框

    //新创建一个类
    #import <UIKit/UIKit.h>
    
    typedef NS_ENUM(NSInteger, XFNoticesStyle) {
        XFNoticesStyleSuccess  = 0,
        XFNoticesStyleFail     = 1,
    };
    
    @interface XFNotices : UIView
    
    //创建方法
    +(void)noticesWithTitle:(NSString *)title Time:(NSTimeInterval)time View:(UIView *)view Style:(XFNoticesStyle)style;
    
    @end
    
    .m 文件中
    
    #import "XFNotices.h"
    
    @interface XFNotices ()
    
    @property (nonatomic, strong)UIImageView *image;
    @property (nonatomic, strong)UILabel *message;
    @property (nonatomic, strong)NSDictionary *dic;
    
    @end
    
    @implementation XFNotices
    
    - (instancetype)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            [self setupView];
            
        }
        return self;
    }
    - (void)setupView { self.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.9]; self.image = [[UIImageView alloc]init]; _image.frame = CGRectMake(34, 10, 32, 32); _image.image = [UIImage imageNamed:@"success"]; [self addSubview:_image]; self.message = [[UILabel alloc]init]; _message.frame = CGRectMake(10, 45, 80, 30); _message.textAlignment = NSTextAlignmentCenter; _message.textColor = [UIColor whiteColor]; _message.numberOfLines = 0; [self addSubview:_message]; } +(void)noticesWithTitle:(NSString *)title Time:(NSTimeInterval)time View:(UIView *)view Style:(XFNoticesStyle)style { XFNotices *notices = [[XFNotices alloc]initWithFrame:CGRectMake(0,0, 100, 80)]; switch (style) { case 0: notices.image.image = [UIImage imageNamed:@"success"]; break; case 1: notices.image.image = [UIImage imageNamed:@"fail"]; default: break; } notices.center = CGPointMake(view.bounds.size.width / 2, view.bounds.size.height/2 - 100); notices.layer.masksToBounds = YES; notices.layer.cornerRadius = 15; notices.dic = [NSDictionary dictionaryWithObject:notices forKey:@"dd"]; notices.message.text = title; notices.message.font = [UIFont systemFontOfSize:12]; notices.alpha = 0; [UIView animateWithDuration:0.5 animations:^{ notices.center = CGPointMake(view.bounds.size.width / 2, view.bounds.size.height/2 - 100); [view addSubview:notices]; notices.alpha = 0.7; }]; [NSTimer scheduledTimerWithTimeInterval:time target:self selector:@selector(timeAction:) userInfo:notices.dic repeats:NO]; } + (void)timeAction:(NSTimer *)sender { XFNotices *notices = [[sender userInfo] valueForKey:@"dd"]; [UIView animateWithDuration:0.5 animations:^{ notices.alpha = 0; } completion:^(BOOL finished) { [notices removeFromSuperview]; }]; } @end
  • 相关阅读:
    Linux虚拟内存(swap)调优篇-“swappiness”,“vm.dirty_background_ratio”和“vm.dirty_ratio”
    《Kafka权威指南》读书笔记-操作系统调优篇
    HTML&CSS基础-表单简介
    《Apache Kafka 实战》读书笔记-认识Apache Kafka
    HTML&CSS基础-完善clearfix
    HTML&CSS基础-使用表格布局
    比Kafka Mangaer更优秀的开源监控工具-Kafka Eagle
    Kafka吞吐量测试案例
    flume常见异常汇总以及解决方案
    运维监控-Open-Falcon单机部署实战篇
  • 原文地址:https://www.cnblogs.com/aiyiran/p/5036514.html
Copyright © 2011-2022 走看看