iOS界面编程-UIAlertView

一、介绍

UIAlertView这个视图控件在iOS8以后不再使用转而使用UIAlertController,UIAlertView主要用给用户显示警告信息,提示用户注意。UIAlertView跟action sheet类似,主要在外表上有所区别。

二、相关属性及方法

初始化alert view

- (instancetype nonnull)initWithTitle:(NSString * nullable)title
                              message:(NSString * nullable)message
                             delegate:(id nullable)delegate
                    cancelButtonTitle:(NSString * nullable)cancelButtonTitle
                    otherButtonTitles:(NSString * nullable)otherButtonTitles,


@property(nonatomic,weak) iddelegate

@property(nonatomic,copy) NSString *title

@property(nonatomic,copy)NSString *message;  


增加一个按钮和其文字,并返回其增加的序列,按钮按照其增加的先后进行排序,按钮不能被自定义。

- (NSInteger)addButtonWithTitle:(NSString *)title;   // returns index of button. 0 based.

- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex; 返回某个序列中按钮的文字。

@property(nonatomic,readonly)NSInteger numberOfButtons; 返回按钮的个数。

@property(nonatomic)NSInteger cancelButtonIndex;     // if the delegate does not implement -alertViewCancel:, we pretend this button was clicked on. default is -1


@property(nonatomic,readonly)NSInteger firstOtherButtonIndex;// -1 if no otherButtonTitles or initWithTitle:... not used

@property(nonatomic,readonly,getter=isVisible)BOOL visible;

- (void)show;

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;


// alert显示给用户的类型,iOS5以后可以用。默认UIAlertViewStyleDefault

@property(nonatomic,assign)UIAlertViewStyle alertViewStyle __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);


/* Retrieve a text field at an index - raises NSRangeException when textFieldIndex is out-of-bounds. 

   The field at index 0 will be the first text field (the single field or the login field), the field at index 1 will be the password field. */

- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex__OSX_AVAILABLE_STARTING(__MAC_NA,


三使用例子

    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登录", nil];
    alertView.title =@"用户登录";
    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
    [alertView show];


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSString *titleButon= [alertView buttonTitleAtIndex:buttonIndex];
    if ([titleButon isEqualToString:@"登录"]) {
        NSString *userName= [alertView textFieldAtIndex:0].text;
        NSString *password= [alertView textFieldAtIndex:1].text;
        NSLog(@"userName=%@,password=%@",userName,password);

    }
}

控制台输出:

2015-10-09 09:47:19.280 Xcode_learn[1317:50099] userName=tyyt,password=hhhh




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

house.zhang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值