13、UITextField-OC+UI

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的其他任意位置,键盘自动收起:

必须增加这行:

事件:


关于键盘弹出和收起的通知:

【键盘会挡住按钮】

让键盘升起的时候让按钮也升起来

定义键盘升起系统通知:

升起按钮事件:

定义键盘收起系统通知:


收起按钮事件:






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值