iOS开发笔记-ios7 UIAlertView自定义
来源:互联网 发布:php json数组格式 编辑:程序博客网 时间:2024/06/05 18:42
之前一个项目适配ios7之后,发现原先的UIAlertView无法正常显示。
后来发现ios7里面原生态的UIAlertView不支持自定义了。
然后就去github上找了下。发现了一个不错的第三方库。和我们之前的使用习惯差不多。
mark一下。
下面给个简单的示例。
1.导入文件。
将这两个文件加入我们的工程下。
2.添加头文件
在需要使用UIAlertView的地方,添加头文件。
#import "CustomIOS7AlertView.h"
并且添加协议。比如我的.h文件
#import <uikit uikit.h="">#import "CustomIOS7AlertView.h" @interface ViewController : UIViewController<customios7alertviewdelegate> @end</customios7alertviewdelegate></uikit>
3.添加UIAlertView
先给出.m文件。
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad{ [super viewDidLoad]; // Just a subtle background color [self.view setBackgroundColor:[UIColor colorWithRed:0.8f green:0.8f blue:0.8f alpha:1.0f]]; // A simple button to launch the demo UIButton *launchDialog = [UIButton buttonWithType:UIButtonTypeCustom]; [launchDialog setFrame:CGRectMake(10, 30, self.view.bounds.size.width-20, 50)]; [launchDialog addTarget:self action:@selector(launchDialog:) forControlEvents:UIControlEventTouchDown]; [launchDialog setTitle:@"Launch Dialog" forState:UIControlStateNormal]; [launchDialog setBackgroundColor:[UIColor whiteColor]]; [launchDialog setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; [launchDialog.layer setBorderWidth:0]; [launchDialog.layer setCornerRadius:5]; [self.view addSubview:launchDialog];} - (IBAction)launchDialog:(id)sender{ // Here we need to pass a full frame CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init]; // Add some custom content to the alert view [alertView setContainerView:[self createDemoView]]; // Modify the parameters [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Close1", @"Close2", @"Close3", nil]]; [alertView setDelegate:self]; // You may use a Block, rather than a delegate. [alertView setOnButtonTouchUpInside:^(CustomIOS7AlertView *alertView, int buttonIndex) { NSLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]); [alertView close]; }]; [alertView setUseMotionEffects:true]; // And launch the dialog [alertView show];} - (void)customIOS7dialogButtonTouchUpInside: (CustomIOS7AlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex{ NSLog(@"Delegate: Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]); [alertView close];} - (UIView *)createDemoView{ UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 200)]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)]; [imageView setImage:[UIImage imageNamed:@"demo"]]; [demoView addSubview:imageView]; return demoView;} @end
这里,通过一个button绑定弹出UIAlertView。 当然,你也可以在其他条件触发launchDialog方法。
然后UIAlertView载入自己定义的视图(createDemoView)。
另外,块内的setOnButtonTouchUpInside 和 单独的delegate customIOS7dialogButtonTouchUpInside方法都能响应我们的选择。
具体选择哪种方式因人而异。
下面给出例子程序下载链接:http://download.csdn.net/detail/hitwhylz/6857765
学习的路上,与君共勉。
原文地址:http://www.2cto.com/kf/201401/273343.html 0 0
- iOS开发笔记-ios7 UIAlertView自定义
- iOS开发-ios7 UIAlertView自定义
- ios ios7 UIAlertView自定义
- ios7 UIAlertView自定义
- ios 自定义UiAlertView
- ios 自定义UIAlertView
- iOS自定义UIAlertView
- ios7中不支持自定义UIAlertView的样式
- Android 自定义Dialog 实现类似ios7 UIAlertView
- IOS 7 自定义的UIAlertView不能在iOS7上正常显示
- IOS7学习之路九(ios7自定义UIAlertView)
- iOS开发之如何自定义UIActionSheet(UIAlertView)中的内容
- iOS开发之自定义系统的UIAlertView调整Alert字体
- ios学习笔记 UIAlertView
- 【iOS学习笔记】UIalertview
- UIAlertView警报-IOS开发
- IOS开发:UIAlertView使用
- iOS开发-UIAlertView
- JS直接粘贴功能
- Tomcat中的设计模式一
- 数据结构-红黑树扩张-顺序统计树
- 第二讲 探秘微信公众号 转自:walkingmanc的专栏
- soap 简单对象访问协议
- iOS开发笔记-ios7 UIAlertView自定义
- Android模拟键盘和键盘监听的一些调研
- Eclipse+CDT+gdb调试android ndk程序
- oracle创建表空间和用户
- 百度质量部的面试体验之 一面
- jQuery子窗体取得父窗体的元素
- 从程序员到项目经理
- 关于cygwin的“-$'\r': command not found和syntax error: unexpected end of file
- 安装Windows7步骤