iOS 基础小结 常用控件之二
来源:互联网 发布:json 汉字 不转义 编辑:程序博客网 时间:2024/06/06 01:36
一,UIAlertView警告框
(1) UIAlertView * alert = [[UIAlertViewalloc]
initWithTitle:@"Notice"message:@"the alert"delegate:selfcancelButtonTitle:@"OK"otherButtonTitles:@"Options1",@"Options2",nil];
[alert show];
很简单,上述方法可以产生并显示一个警告框。警告框上的button的内容就是设置ButtonTitle。关键是警告框给提供的协议方法。(2)
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
这个方法是当用户点击警告框中的某个按键时会触发该方法,buttonIndex代表按钮的索引,从0开始
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
这个方法是完全隐藏警示框出来之后会触发
- (void)alertViewCancel:(UIAlertView *)alertView
这个是在警告框被取消时触发
- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
这个方法是在将要显示隐藏的时候触发- (void)willPresentAlertView:(UIAlertView *)alertView
这个是警告框将要显示出来的时候触发-(void) didPresentAlertView:(UIAlertView *)alertView
这个是警告框完全显示出来的时候触发(3)该控件有个属性,actionSheetStyle,用来设置风格,比如可以使其带有一个输入框,带有密码输入框等,举个栗子,输入用户名和密码
- (IBAction)clicked:(id)sender {
UIAlertView * alert = [[UIAlertViewalloc]
initWithTitle:@"Log on"message:@"please input the user name and the password"delegate:selfcancelButtonTitle:@"Cancle"otherButtonTitles:@"OK",nil];
alert.alertViewStyle =UIAlertViewStyleLoginAndPasswordInput;
[alert textFieldAtIndex:1].keyboardType =UIKeyboardTypeNumberPad;
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
UITextField * nameField = [alertViewtextFieldAtIndex:0];
UITextField * passField = [alertViewtextFieldAtIndex:1];
NSString * msg = [NSStringstringWithFormat:@"you have input the user name : %@ and the password : %@",nameField.text,passField.text];
UIAlertView * alert = [[UIAlertViewalloc]initWithTitle:@"notice"message:msgdelegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil];
[alert show];
}
}
- (void) willPresentAlertView:(UIAlertView *)alertView{
for (UIView * viewin alertView.subviews) {
if ([view isKindOfClass:[UILabelclass]]) {
UILabel * lable = (UILabel *)view;
lable.textAlignment =UITextAlignmentLeft;
}
}
}
二,UIActionSheet
这个控件跟Alert非常之像,写一点简单的使用就可以知道了
- (IBAction)clicked:(id)sender {
UIActionSheet * sheet = [[UIActionSheetalloc]initWithTitle:@"make sure to delete"delegate:selfcancelButtonTitle:@"Cancle"destructiveButtonTitle:@"OK"otherButtonTitles:@"Options1",@"Options2",nil];
sheet.actionSheetStyle =UIActionSheetStyleAutomatic;
[sheet showInView:self.view];
}
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString * msg = [NSStringstringWithFormat:@"you have clicked the %ld button",(long)buttonIndex];
UIAlertView * alert = [[UIAlertViewalloc]initWithTitle:@"notice"message:msg delegate:nilcancelButtonTitle:@"OK"otherButtonTitles: nil];
[alert show];
}
- iOS 基础小结 常用控件之二
- iOS 基础小结之常用控件 一
- iOS 基础小结之常用控件三
- IOS基础控件(二)
- ios基础控件之UITextField常用方法汇总
- ios常用控件(二)
- iOS基础之OC简单控件知识了解(二)
- iOS基础常用控件简介
- iOS基础控件之UISegmentedControl
- ios基础控件之UITextView
- IOS 控件之基础整理
- IOS之基础控件(一)
- 学习ios之基础控件
- iOS 开发基础常用控件介绍总结
- iOS入门(二十五)基础控件
- ios学习笔记(二)基础控件
- iOS开发UI基础—25UITableview控件使用小结
- iOS开发UI基础—10常用UI控件综合示例之QQ音乐
- poj 2187(凸包)
- 为YUM设置代理的方法
- iOS_21团购_地图功能
- UVa 355 - The Bases Are Loaded
- 飞机长一样的平
- iOS 基础小结 常用控件之二
- 剑指Offer19二叉树的镜像
- Matlab学习-------GUI鼠标事件响应(鼠标划线实例)
- 魔方阵
- qwerfsdfgd去wesjdf
- 工作日志2014-08-21
- IOS 多个UIImageView 加载高清大图时内存管理
- 全wetasdf
- 去werfdfjkg