自定义UIAlertView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.windowLevel = UIWindowLevelAlert;
        self.frame = [UIScreen mainScreen].bounds;
        
    }
    return self;
}

上面设置为警告框类型的

//
//  CustomAlertView.m
//  太平人寿项目
//
//  Created by lanqs on 15/2/6.
//  Copyright (c) 2015年 Tanqihong. All rights reserved.
//

#import "CustomAlertView.h"

@interface CustomAlertView () {
    UIView *view;
    CGPoint _point;
    NSTimer *_timer;
}

@end

@implementation CustomAlertView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.windowLevel = UIWindowLevelAlert;
        self.frame = [UIScreen mainScreen].bounds;
        
    }
    return self;
}

- (void)show:(NSString *)string {
    UIView *backGroundView = [[UIView alloc]initWithFrame:self.bounds];
    backGroundView.backgroundColor = [UIColor blackColor];
    backGroundView.alpha = 0.3;
    [self addSubview:backGroundView];
    
    view = [[UIView alloc]init];
    view.bounds = CGRectMake(0, 0,CGRectGetWidth(self.bounds) * 0.6, CGRectGetWidth(self.bounds) * 0.2);
    view.layer.cornerRadius = 10;
    view.clipsToBounds = YES;
    view.backgroundColor = [UIColor whiteColor];
    view.center = CGPointMake(CGRectGetWidth(self.bounds)/2, CGRectGetHeight(self.bounds)/2);
    _point = view.center;
    [self addSubview:view];
    
    UILabel *lable = [[UILabel alloc]init];
    lable.bounds = CGRectMake(0, 0, CGRectGetWidth(view.bounds) - 40, 30);
    lable.center = CGPointMake(CGRectGetWidth(view.bounds)/2, CGRectGetHeight(view.bounds)/2);
    lable.textColor = [UIColor grayColor];
    lable.textAlignment = NSTextAlignmentCenter;
    lable.text = string;
    [view addSubview:lable];
    _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(viewAnimation) userInfo:nil repeats:YES];
//    _timer.fireDate = [NSDate distantFuture];
    [self makeKeyAndVisible];
}

- (void)viewAnimation {
//    _timer.fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
    [UIView animateWithDuration:0.5 animations:^{
        view.center = CGPointMake(_point.x, _point.y + 10);
    } completion:^(BOOL finished) {
       [UIView animateWithDuration:0.5 animations:^{
            view.center = CGPointMake(_point.x, _point.y);
       }];
    }];
}

- (void)hidenView {
    [UIView animateWithDuration:0.5 animations:^{
        self.alpha = 0.3;
    }];
    [self performSelector:@selector(timer) withObject:self afterDelay:0.5];
}

- (void)timer {
    self.hidden = YES;
    _timer.fireDate = [NSDate distantFuture];
}

- (void)showstart {
    
    self.hidden = NO;
    _timer.fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
    
}
@end

调用:

@property (nonatomic,strong)CustomAlertView * window;

    _window = [[CustomAlertView alloc] init];
    [_window show:@"请等待..."];

记着隐藏

   [_window hidenView];

效果图:


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值