UIAlertView
主要功能:用于提示用户相关信息,并与用户进行交互,比如给用户提供选择或确认。
UILertView常用属性和初始化放法
UIAlertViewStyle *alertViewStyle
1.UIAlertViewStyleDefault = 0;
2.UIAlertViewStyleSecureTextInput;
3.UIAlertViewStylePlainTextInput;
4.UIAlertViewStyleLoginAndPasswordInput;
id/ * <UIAlertViewDelegate> * / delegate;
- (id)initWithTitle:(NSString*)title message:( NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString*)cancelButtonTitle otherButtonTitles:(NSString*)otherButtonTitles,...
- (void)show;
- (Void)alertView:(UIAlterView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
实例:
UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:
@"警告" message:
@"你的用户名或者密码有误,请根据实际情况来确认详细信息,并进行再次操作" delegate:self cancelButtonTitle:
@"取消" otherButtonTitles:
@"确认", nil];
alerView.alertViewStyle = UIAlertViewStyleSecureTextInput;
[alerView show];
UIActionSheet
主要功能:主要是从屏幕下方弹出提示信息提示用户
UIActionSheet常用属性和初始化方法
- (id)initWithTitle:(NSStirng *)title delegate:
(id<UIActionSheetDelegate>)delegate cancelButtonTitle:(NSString*)destructiveButtonTitle otherButtonTitle:(NSString *)otherButtonTitles,...
- (void)showInView:(UIView *)view;
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
UIActionSheet代码展示
@interface ViewController ()<UIActionSheetDelegate>
- (IBAction)onButton:(id)sender forEvent:(UIEvent *)event {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"警告" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确认" otherButtonTitles:@"hahah", nil];
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%ld",buttonIndex);
switch (buttonIndex) {
case 0:
NSLog(@"用户点击了确认按钮");
break;
case 1:
NSLog(@"用户点击了hello");break;
case 2:
NSLog(@"用户点击了取消按钮");break;
default:
break;
}
}