实现带输入框的AlertView及设置键盘样式的方法
来源:互联网 发布:买车app软件 编辑:程序博客网 时间:2024/06/14 14:32
对于带输入框的弹出框(UIAlertView),在IOS5.0及以上版本,有一种较为简单的实现方式,即设置UIAlertView的alertViewStyle属性即可。
可供设置的属性如下:
UIAlertViewStyleDefault,为默认值,不带输入框
UIAlertViewStyleSecureTextInput为密码型输入框,输入的字符显示为圆点儿
UIAlertViewStylePlainTextInput为明文输入框,显示输入的实际字符
UIAlertViewStyleLoginAndPasswordInput为用户名,密码两个输入框,一个明文,一个密码。
取得输入框指针的方法如下:
对于UIAlertViewStyleSecureTextInput和UIAlertViewStylePlainTextInput两种情况,
UITextField *tf = [alert textFieldAtIndex:0]即可取到输入框指针,然后可以进行具体的操作,包括设置键盘样式
对于UIAlertViewStyleLoginAndPasswordInput,除了上面的输入框,依次类推,还可以取到第二个输入框,即:
UITextField *tf2 = [alert textFieldAtIndex:1]
设置键盘样式的方法,即设置UITextField的keyboardType属性。具体值如下:
示例代码:
原文地址:[url]http://bluevt.org/?p=103[/url]
可供设置的属性如下:
1
2
3
4
5
6
typedef
NS_ENUM
(
NSInteger
, UIAlertViewStyle) {
UIAlertViewStyleDefault = 0,
UIAlertViewStyleSecureTextInput,
UIAlertViewStylePlainTextInput,
UIAlertViewStyleLoginAndPasswordInput
};
UIAlertViewStyleDefault,为默认值,不带输入框
UIAlertViewStyleSecureTextInput为密码型输入框,输入的字符显示为圆点儿
UIAlertViewStylePlainTextInput为明文输入框,显示输入的实际字符
UIAlertViewStyleLoginAndPasswordInput为用户名,密码两个输入框,一个明文,一个密码。
取得输入框指针的方法如下:
对于UIAlertViewStyleSecureTextInput和UIAlertViewStylePlainTextInput两种情况,
UITextField *tf = [alert textFieldAtIndex:0]即可取到输入框指针,然后可以进行具体的操作,包括设置键盘样式
对于UIAlertViewStyleLoginAndPasswordInput,除了上面的输入框,依次类推,还可以取到第二个输入框,即:
UITextField *tf2 = [alert textFieldAtIndex:1]
设置键盘样式的方法,即设置UITextField的keyboardType属性。具体值如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
typedef
NS_ENUM
(
NSInteger
, UIKeyboardType) {
UIKeyboardTypeDefault,
// Default type for the current input method.
UIKeyboardTypeASCIICapable,
// Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation,
// Numbers and assorted punctuation.
UIKeyboardTypeURL,
// A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad,
// A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad,
// A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad,
// A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress,
// A type optimized for multiple email address entry (shows space @ . prominently).
#if __IPHONE_4_1 <= __IPHONE_OS_VERSION_MAX_ALLOWED
UIKeyboardTypeDecimalPad,
// A number pad with a decimal point.
#endif
#if __IPHONE_5_0 <= __IPHONE_OS_VERSION_MAX_ALLOWED
UIKeyboardTypeTwitter,
// A type optimized for twitter text entry (easy access to @ #)
#endif
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,
// Deprecated
};
示例代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
- (
IBAction
)pressed:(
id
)sender
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@
"message"
message:@
"please input"
delegate:
nil
cancelButtonTitle:@
"cancel"
otherButtonTitles:@
"OK"
,
nil
];
// 基本输入框,显示实际输入的内容
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
// 用户名,密码登录框
// alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
// 密码形式的输入框,输入字符会显示为圆点
// alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
//设置输入框的键盘类型
UITextField *tf = [alert textFieldAtIndex:0];
tf.keyboardType = UIKeyboardTypeNumberPad;
UITextField *tf2 =
nil
;
if
(alert.alertViewStyle == UIAlertViewStyleLoginAndPasswordInput) {
// 对于用户名密码类型的弹出框,还可以取另一个输入框
tf2 = [alert textFieldAtIndex:1];
tf2.keyboardType = UIKeyboardTypeASCIICapable;
}
// 取得输入的值
NSString
* text = tf.text;
NSLog
(@
"INPUT:%@"
, text);
if
(alert.alertViewStyle == UIAlertViewStyleLoginAndPasswordInput) {
// 对于两个输入框的
NSString
* text2 = tf2.text;
NSLog
(@
"INPUT2:%@"
, text2);
}
[alert show];
[alert release];
}
原文地址:[url]http://bluevt.org/?p=103[/url]
0 0
- 实现带输入框的AlertView及设置键盘样式的方法
- 实现带输入框的AlertView及设置键盘样式的方法
- 带输入框的AlertView
- iOS中键盘样式设置、隐藏系统键盘的方法
- UIAlertController的AlertView形式 加输入框 用法
- 键盘挡住输入框的处理方法
- ios——带文本框的alertView
- 用样式设置页面文本框 只能输入数字的方法
- 输入框随键盘移动的实现
- TextBox弹出的输入键盘的设置及限制输入功能
- 键盘风格 及设置键盘的inputView
- Alert--兼容iOS7及以上的AlertView,支持设置对齐方式,支持设置行间距
- android-弹出键盘以及输入框的设置
- 在html输入框中响应enter键盘------介绍重要的onkeydown方法实现“模糊查找”
- Xcode6设置模拟器键盘的中文输入
- 关于自定义AlertView背景的方法收集
- 关于自定义AlertView背景的方法收集
- 关于自定义AlertView背景的方法收集
- Mac 下SVN 命令
- Android4.1 关于Rotation相关的Configuration整体分析2
- 虛函数详解
- 数据库服务器的存储换硬盘前,oracle数据库的冷备份
- 关于大一上学期学习JAVA的见解
- 实现带输入框的AlertView及设置键盘样式的方法
- 备份SVN
- IOS GCD的介绍及使用举例&GCD优先级改变、after、group、barrier、sync、apply、semaphore、o
- 读《团队之美》
- Android4.1 关于Rotation相关的Configuration整体分析3
- MATLAB中getframe应用函数举例
- PAT A1009 Product of Polynomials
- mysql处理高并发,防止库存超卖
- TableLayout居中