#import "RootViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton* button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(10, 100, 120, 60);
button.backgroundColor=[UIColor redColor];
[self.view addSubview:button];
[button addTarget:self action:@selector(touchme) forControlEvents:UIControlEventTouchUpInside];
}
-(void)touchme{
// 提示框(新版)
UIAlertController* control =[UIAlertController alertControllerWithTitle:@"友情提示" message:@"是否购买" preferredStyle:UIAlertControllerStyleAlert];
// UIAlertController* control =[UIAlertController alertControllerWithTitle:@"友情提示" message:@"是否购买" preferredStyle:UIAlertControllerStyleActionSheet];
//添加选项
// UIAlertAction* act1=[UIAlertAction actionWithTitle:@"买" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// NSLog(@"买了");
// }];
// UIAlertAction* act2=[UIAlertAction actionWithTitle:@"不买" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
// NSLog(@"没钱");
// }];
// 红色的那个选项
// UIAlertAction* act3=[UIAlertAction actionWithTitle:@"红色" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
//
// }];
//添加选项卡
// [control addAction:act1];
// [control addAction:act2];
// [control addAction:act3];
[self presentViewController:control animated:YES completion:^{
NSLog(@"弹出来了");
} ];
//定时器 repeats Yes 表示间隔 时间运行 No表示只有一次
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeOut) userInfo:nil repeats:YES];
}
-(void)timeOut{
NSLog(@"取消提示框");
[self dismissViewControllerAnimated:YES completion:^{
}];
};
@end