iOS 开发之带输入框的UIAlertView
2015-11-14 23:31
246 查看
//
// ViewController.m
// 1114带输入框的UIAlertView
//
// Created by weibiao on 15/11/14.
// Copyright © 2015年 weibiao. All rights reserved.
//
#import "ViewController.h"
@interface
ViewController ()<UIAlertViewDelegate>
- (IBAction)btnClick:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
}
- (IBAction)btnClick:(id)sender {
// UIAlertViewStyle *alertV = [];
UIAlertView *alertV = [[UIAlertView
alloc] initWithTitle:@"登陆"
message:@"请输入用户名和密码登陆系统"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",
nil];
alertV.alertViewStyle =
UIAlertViewStyleLoginAndPasswordInput;
[alertV textFieldAtIndex:1].keyboardType =
UIKeyboardTypeNumberPad;
[alertV show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex ==
1) {
//
获取UIAlertView中第一个输入框
UITextField *loginTextField = [alertView
textFieldAtIndex:0];
//
获取UIAlertView中的第二个输入框
UITextField *passwardTextField = [alertView
textFieldAtIndex:1];
//
拼接TextField字符串
NSString *msg = [NSString
stringWithFormat:@"您输入的用户名是:%@,密码是:%@",loginTextField.text,passwardTextField.text];
UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:@"提示"
message:msg delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
}
}
- (void)willPresentAlertView:(UIAlertView *)alertView {
//
遍历UIalertView包含的全部子控件
for (UIView *view
in alertView.subviews) {
//
如果该子控件是UILabel控件
if ([view
isKindOfClass:[UILabel
class]]) {
UILabel *label = (UILabel *)view;
//
将UILabel的文字对齐方式设为左对齐
label.textAlignment =
NSTextAlignmentLeft;
}
}
}
@end
// ViewController.m
// 1114带输入框的UIAlertView
//
// Created by weibiao on 15/11/14.
// Copyright © 2015年 weibiao. All rights reserved.
//
#import "ViewController.h"
@interface
ViewController ()<UIAlertViewDelegate>
- (IBAction)btnClick:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
}
- (IBAction)btnClick:(id)sender {
// UIAlertViewStyle *alertV = [];
UIAlertView *alertV = [[UIAlertView
alloc] initWithTitle:@"登陆"
message:@"请输入用户名和密码登陆系统"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",
nil];
alertV.alertViewStyle =
UIAlertViewStyleLoginAndPasswordInput;
[alertV textFieldAtIndex:1].keyboardType =
UIKeyboardTypeNumberPad;
[alertV show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex ==
1) {
//
获取UIAlertView中第一个输入框
UITextField *loginTextField = [alertView
textFieldAtIndex:0];
//
获取UIAlertView中的第二个输入框
UITextField *passwardTextField = [alertView
textFieldAtIndex:1];
//
拼接TextField字符串
NSString *msg = [NSString
stringWithFormat:@"您输入的用户名是:%@,密码是:%@",loginTextField.text,passwardTextField.text];
UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:@"提示"
message:msg delegate:self
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
}
}
- (void)willPresentAlertView:(UIAlertView *)alertView {
//
遍历UIalertView包含的全部子控件
for (UIView *view
in alertView.subviews) {
//
如果该子控件是UILabel控件
if ([view
isKindOfClass:[UILabel
class]]) {
UILabel *label = (UILabel *)view;
//
将UILabel的文字对齐方式设为左对齐
label.textAlignment =
NSTextAlignmentLeft;
}
}
}
@end
相关文章推荐
- 基于POM(page oriented model)的UI测试脚本编写
- IOS之UIImageView--小实例项目--带音效的拳皇动画
- Arduino与Android蓝牙通信笔记
- easyui datagrid 编辑状态时,为列添加文本改变事件
- Dimensionality Reduction Techniques for Data Visualization
- 杭电ACM3117——Crixalis's Equipment
- 设计模式-生成器模式(Builder)
- require学习笔记总结
- confluence5.8.10的使用
- [置顶] 基于IBM Bluemix部署Java Web项目实战演练
- Codeforces Round #276 (Div. 1)B. Maximum Value 筛法
- Java中双等号和equeals的区别
- 玩转tableViewCell 侧滑按钮UITableViewCellDeleteConfirmationView
- 225 Implement Stack using Queues
- 232 Implement Queue using Stacks
- 每天学一点easyui②
- RMQ(Range Minimum Query)问题(转)
- 隐藏uitabbar的代码
- UVa133 - The Dole Queue
- UISwitch(开关控件)、UISegmentedControl(分段控件)