有时候系统的UIAlertView不一定能够满足我们的编程需求,需要我们自定义alertView,我写了一个简单的定义了界面有三种类型
效果如下所示
demo:http://download.csdn.net/detail/tuwanli125/9470335
demo地址:https://github.com/tuwanli/DefinedSelf
只需要在你的控制器里面写入提示文字:
//
// ViewController.m
// DefinedSelf
//
// Created by 涂婉丽 on 15/12/15.
// Copyright © 2015年 涂婉丽. All rights reserved.
//
#import "ViewController.h"
#import "TWLAlertView.h"
@interface ViewController ()<TWlALertviewDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
}
- (IBAction)click {
[selfloadAlertView:@"创建一个就诊号"contentStr:@"注:新建就诊号,以前的就诊信息无法查询,第一次在手机挂号到医院分诊台分诊时需要出示身份证,如果挂号填写的就诊人信息和身份证信息不符,医院有权利拒绝提供就诊服务,挂号费用不退"btnNum:2btnStrArr:[NSArrayarrayWithObjects:@"取消",@"确定",nil]type:10];
}
- (IBAction)clicktwo {
[selfloadAlertView:@"请输入密码"contentStr:nilbtnNum:2btnStrArr:[NSArrayarrayWithObjects:@"取消",@"确定",nil] type:11];
}
- (IBAction)clickThree {
[selfloadAlertView:@"常用就诊人"contentStr:@"是否删除就诊人"btnNum:1btnStrArr:[NSArrayarrayWithObject:@"退出页面"]type:12];
}
- (void)loadAlertView:(NSString *)title contentStr:(NSString *)content btnNum:(NSInteger)num btnStrArr:(NSArray *)array type:(NSInteger)typeStr
{
TWLAlertView *alertView = [[TWLAlertViewalloc]initWithFrame:CGRectMake(0,0, [UIScreenmainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
[alertViewinitWithTitle:title contentStr:content type:typeStr btnNum:num btntitleArr:array];
alertView.delegate =self;
UIView * keywindow = [[UIApplicationsharedApplication] keyWindow];
[keywindowaddSubview: alertView];
}
-(void)didClickButtonAtIndex:(NSUInteger)index password:(NSString *)password{
switch (index) {
case 101:
NSLog(@"Click ok");
break;
case 100:
NSLog(@"Click cancle");
break;
default:
break;
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
在TWLAlertView里面定义alertView弹出框的所有子视图,以及弹出动画
-(void)exChangeOut:(UIView *)changeOutView dur:(CFTimeInterval)dur{
CAKeyframeAnimation * animation;
animation = [CAKeyframeAnimationanimationWithKeyPath:@"transform"];
animation.duration = dur;
animation.removedOnCompletion =NO;
animation.fillMode =kCAFillModeForwards;
NSMutableArray *values = [NSMutableArrayarray];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.1,0.1,1.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(1.2,1.2,1.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.9,0.9,0.9)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(1.0,1.0,1.0)]];
animation.values = values;
animation.timingFunction = [CAMediaTimingFunctionfunctionWithName:@"easeInEaseOut"];
[changeOutView.layeraddAnimation:animationforKey:nil];
}