iOS 9 的 UIAlertViewController
2016-01-08 16:54
399 查看
话不多说 直接 上代码 。。。
UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(50, 100, 50, 50)];
myView.backgroundColor = [UIColor redColor];
[self.view addSubview:myView];
UIImageView *imageViews = [[UIImageView alloc]init];
imageViews.frame = myView.frame;
imageViews.backgroundColor = [UIColor yellowColor];
[self.view addSubview:imageViews];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(rightAction:)];
[myView addGestureRecognizer:tap];
- (void)rightAction:(UIBarButtonItem *)sender
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//preferredStyle 为 UIAlertControllerStyleActionSheet 时跳出 为 ActionSheet
// preferredStyle 为 UIAlertControllerStyleActionAlert 时 跳出为 AlertView
[alert addAction:[UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"相机...");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"相册...");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"取消...");
}]];
// 特别重要 的 必须得 模态出来
[self presentViewController:alert animated:YES completion:nil];
}
UIView *myView = [[UIView alloc]initWithFrame:CGRectMake(50, 100, 50, 50)];
myView.backgroundColor = [UIColor redColor];
[self.view addSubview:myView];
UIImageView *imageViews = [[UIImageView alloc]init];
imageViews.frame = myView.frame;
imageViews.backgroundColor = [UIColor yellowColor];
[self.view addSubview:imageViews];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(rightAction:)];
[myView addGestureRecognizer:tap];
- (void)rightAction:(UIBarButtonItem *)sender
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//preferredStyle 为 UIAlertControllerStyleActionSheet 时跳出 为 ActionSheet
// preferredStyle 为 UIAlertControllerStyleActionAlert 时 跳出为 AlertView
[alert addAction:[UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"相机...");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"相册...");
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"取消...");
}]];
// 特别重要 的 必须得 模态出来
[self presentViewController:alert animated:YES completion:nil];
}
相关文章推荐
- UIScrollView详解
- <LeetCode OJ> 62. Unique Paths
- Build Path的作用
- iOS UI三大控件和应用程序启动流程
- UIpageController基本属性
- OpenLayers.2.10.Beginners.Guide---第一章
- xib在UITableView中的用法
- iOS开发之UICollectionView(一)
- UITextView高度根据内容变化
- SWT UI线程下另开线程执行数据处理和发送功能(多线程处理)
- iOS 使用UIBezierPath与CABasicAnimation绘制图形
- 老李分享:接电话扩展之uiautomator 2
- 老李分享:接电话扩展之uiautomator 1
- oc之字典创建 复制 获取key value值
- 【Android UI】 Shape详解
- uva 11572 - Unique Snowflakes
- UIScrollView页面
- sparksql语法,读parquet,load,save
- UITableView的折叠收缩和QQ好友分组效果
- java中int和integer,String,StringBuffer,StringBuilder的区别