提示框

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

//初始化图片视图

UIImageView *imageView = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];

//设置与用户交互

imageView.userInteractionEnabled = YES;

[self.view addSubview:imageView];

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

btn.frame = CGRectMake(300, 450, 100, 60);

btn.center = CGPointMake(imageView.frame.size.width/2, 500);

[btn setTitle:@"弹出提示" forState:UIControlStateNormal];

btn.backgroundColor = [UIColor whiteColor];

btn.layer.cornerRadius = 20;

btn.layer.masksToBounds = YES;

btn.layer.borderWidth = 1;

btn.layer.borderColor = [UIColor blackColor].CGColor;

[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

[imageView addSubview:btn];

}

-(void)click{

UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"提示" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"注册" otherButtonTitles: nil];

[sheet showInView:self.view];

}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

if (buttonIndex == 0) {

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"注册新用户" message:@"" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];

alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

[alert show];

}

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

UITextField *username = [alertView textFieldAtIndex:0];

UITextField *password = [alertView textFieldAtIndex:1];

NSLog(@"%@-\n--%@",username.text,password.text);

[[[UIAlertView alloc]initWithTitle:@"" message:[NSString stringWithFormat:@"用户名为:%@\n密码为:%@",username.text,password.text] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil] show];

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容