UITextField 属性
UITextField 协议方法:
【用control来收键盘】
关于键盘弹出和收起的通知:
UITextField介绍:
UITextField 常用属性:
#import "ccyAppDelegate.h"
@implementation ccyAppDelegate
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UITextField * textField = [[UITextField alloc] init];
textField.frame = CGRectMake(10, 30, 300, 30);
//设置边框样式
/*
UITextBorderStyleNone, - 无边框+透明
UITextBorderStyleLine, - 黑色边框 + 透明
UITextBorderStyleBezel, - 灰色边框 + 透明
UITextBorderStyleRoundedRect - 圆角边框 + 白色
*/
textField.borderStyle = UITextBorderStyleBezel;
textField.backgroundColor = [UIColor whiteColor];
textField.placeholder = @"请输入密码";
textField.secureTextEntry = YES;
textField.keyboardType = UIKeyboardTypeDecimalPad;
//设置弹出键盘风格
textField.keyboardAppearance = UIKeyboardAppearanceAlert;
//设置弹出视图
// UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
// imageView.frame = CGRectMake(0, 100, 320, 100);
// textField.inputView = imageView;
//设置左视图 图片的长度才有效
UIView * leftview = [[UIView alloc] init];
leftview.frame = CGRectMake(0, 0, 100, 100);
leftview.backgroundColor = [UIColor blueColor];
textField.leftView = leftview;
// 必须设置左视图模式 才能显示左视图
textField.leftViewMode = UITextFieldViewModeAlways;
//清除按钮
textField.clearButtonMode = UITextFieldViewModeAlways;
[self.window addSubview:textField];
[textField release];
//图2
UITextField * textField1 = [[UITextField alloc] init];
textField1.frame = CGRectMake(10, 100, 300, 30);
textField1.borderStyle = UITextBorderStyleBezel;
textField1.backgroundColor = [UIColor whiteColor];
//设置再次编辑清空内容
textField1.clearsOnBeginEditing =YES;
[self.window addSubview:textField1];
[textField1 release];
self.window.backgroundColor = [UIColor redColor];
[self.window makeKeyAndVisible];
return YES;
}
用于web搜索
UITextField 协议方法:
(1)、新增代理
(2)、代理引用
(3)、实现代理
此时:NO:进入该编辑模式后,无法进入旁边的编辑模式【默认是YES】
手动清除内容:【可以写入一些东西】
收起键盘:【取消第一响应者】【点击return 收键盘】
【用control来收键盘】
点击textfield的其他任意位置,键盘自动收起:
必须增加这行:
事件:
关于键盘弹出和收起的通知:
【键盘会挡住按钮】
让键盘升起的时候让按钮也升起来
定义键盘升起系统通知:
升起按钮事件:
定义键盘收起系统通知:
收起按钮事件: