UIAlertView 提醒框

发表于 2018-09-09   |   分类于 Objectiv-C 课程
   //初始化AlertView 
   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"AlertViewTest"  
                                                   message:@"message"  
                                                  delegate:self  
                                         cancelButtonTitle:@"Cancel"  
                                         otherButtonTitles:@"OtherBtn",nil];  
    //设置标题与信息,通常在使用frame初始化AlertView时使用  
    alert.title = @"AlertViewTitle";  
    alert.message = @"AlertViewMessage";  
    //这个属性继承自UIView,当一个视图中有多个AlertView时,可以用这个属性来区分  
    alert.tag = 0;  
  //只读属性,看AlertView是否可见  
    NSLog(@"%d",alert.visible);  
    //通过给定标题添加按钮  
    [alert addButtonWithTitle:@"addButton"];  
    //按钮总数  
    NSLog(@"number Of Buttons :%d",alert.numberOfButtons);  
    //获取取消按钮的索引  
    NSLog(@"cancelButtonIndex:%d",alert.cancelButtonIndex);  
    //获取第一个其他按钮的索引  
    NSLog(@"firstOtherButtonIndex:%d",alert.firstOtherButtonIndex);  
    //显示AlertView  
    [alert show]; 
#pragma marks -- UIAlertViewDelegate --  
//根据被点击按钮的索引处理点击事件  
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  
{  
    NSLog(@"clickButtonAtIndex:%d",buttonIndex);  
}  
 //AlertView已经消失时执行的事件  
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex  
{  
    NSLog(@"didDismissWithButtonIndex");  
}  
  
//ALertView即将消失时的事件  
-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex  
{  
    NSLog(@"willDismissWithButtonIndex");  
}  

发表新评论

© 2019 Powered by Typecho & Theme 豫ICP备15027577号