UIAlertView用法
来源:互联网 发布:注册网络教育公司 编辑:程序博客网 时间:2024/05/17 23:34
1. 最简单的用法
UIAlertView*alert =[[UIAlertView
[alert show];
[alert release];
2. 为UIAlertView添加多个按钮
UIAlertView*alert =[[UIAlertView
[alert show];
[alert release];
UIAlertView有一个委托UIAlertViewDelegate ,继承该委托来实现点击事件
@interface MyAlertViewViewControlle
}
- (void)alertView:(UIAlertView*)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex;
-(IBAction) buttonPressed;
@end
源文件:
-(IBAction) buttonPressed
{
UIAlertView*alert =[[UIAlertView
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView*)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString* msg =[[NSString
UIAlertView* alert =[[UIAlertView
[alert show];
[alert release];
[msg release];
}
点击“取消”,“按钮一”,“按钮二”,“按钮三”的索引buttonIndex分别是0,1,2,3
[alertdismissWithClickedButton
5:为UIAlertView添加子视图
在为UIAlertView对象太添加子视图的过程中,有点是需要注意的地方,如果删除按钮,也就是取消UIAlerView视图中所有的按钮的时候,可能会导致整个显示结构失衡。按钮占用的空间不会消失,我们也可以理解为这些按钮没有真正的删除,仅仅是他不可见了而已。如果在UIAlertview对象中仅仅用来显示文本,那么,可以在消息的开头添加换行符(@"\n)有助于平衡按钮底部和顶部的空间。
下面的代码用来演示如何为UIAlertview对象添加子视图的方法。
UIAlertView*alert =[[UIAlertView
[alert show];
UIActivityIndicatorView*activeView =[[UIActivityIndicatorView
activeView.center =CGPointMake(alert.bounds.size.width/2.0f,alert.bounds.size.height-40.0f);
[activeView startAnimating];
[alert addSubview:activeView];
[activeView release];
[alert release];
中按照自己的需要修改或添加即可, 比如需要将消息文本左对齐,下面的代码即可实现:
-(void)willPresentAlertView:(UIAlertView *)alertView
{
}
添加其他部件也如出一辙, 如下代码添加两个UITextField:
-(void)willPresentAlertView:(UIAlertView *)alertView
{
}
UITextField* accoutName =[[UITextFieldalloc]init];
UITextField* accoutPassword =[[UITextFieldalloc]init];
accoutName.frame = CGRectMake(10, frame.origin.y +40,frame.size.width -20,30 );
accoutPassword.frame = CGRectMake(10, frame.origin.y +80,frame.size.width-20,30 );
accoutName.placeholder =@"请输入账号";
accoutPassword.placeholder =@"请输入密码";
accoutPassword.secureTextEntry =YES;
[alertView addSubview:accoutPassword];
[alertView addSubview:accoutName];
[accoutName release];
[accoutPassword release];
}
对于UIActionSheet其实也是一样的, 在
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
中做同样的处理一样可以得到自己想要的界面。
- UIAlertView用法
- UIAlertView用法
- UIAlertView用法
- UIAlertView用法
- UIAlertView用法
- UIAlertView用法
- UIAlertView用法
- UIAlertView用法
- UIAlertView用法
- UIAlertView用法
- UIAlertView用法
- UIAlertView用法
- UIAlertView的用法
- iPhone入门 - UIAlertView用法
- UIAlertView的 用法
- iPhone入门 - UIAlertView用法
- iPhone入门 - UIAlertView用法
- iPhone入门 - UIAlertView用法
- 图片中识别出图元(2)
- 【最长降序子序列+双向】九度OJ 题目1131:合唱队形
- UIActionSheet用法
- subversion与svn安装配置全过程
- 路由器和交换机的区别
- UIAlertView用法
- 整除规律
- iPhone开发秘籍(一)--第一章 iPhone SDK简介
- Git分支管理策略
- Android工程的自动创建,编译并生成apk
- LR中的参数设置和场景虚拟用户的关联(Unique + each iteration | each occurence | once)
- iPhone开发基础教程笔记(一)--第一章和第二章-创建基本项目
- nginx优化配置
- man 3 printf fprintf sprintf