iOS之自定義彈出框--AlertView

有時候系統的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];

}




發佈了26 篇原創文章 · 獲贊 5 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章