UITextField

UITextField

import “AppDelegate.h”

@interface AppDelegate ()

@end

@implementation AppDelegate

-(void)dealloc{
[_window release];
[super dealloc];
}

  • (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [_window release];

    // 输入框
    UITextField *textField=[[UITextField alloc] initWithFrame:CGRectMake(100, 100, 200, 40)];
    textField.backgroundColor=[UIColor whiteColor];
    [self.window addSubview:textField];
    [textField release];
    // 边框
    textField.layer.borderWidth=1;
    // 圆角
    textField.layer.cornerRadius=10;

    // 实现文本内容
    textField.text=@”测试一下”;
    // 文本颜色
    textField.textColor=[UIColor redColor];
    // 文本对齐方式
    textField.textAlignment=NSTextAlignmentCenter;
    // 文本字体
    textField.font=[UIFont systemFontOfSize:20];

    // 占位文本
    textField.placeholder=@”请输入账号”;

    // 输入密码的时候会把文本变成圆点
    textField.secureTextEntry=YES;

    // 设置不同的键盘类型
    textField.keyboardType=UIKeyboardTypeNumberPad;

    // 改变return的样式
    // 可以把return按钮切换成不同的样式
    textField.returnKeyType=UIReturnKeySearch;

    // 清除上一个写的内容
    textField.clearsOnBeginEditing=YES;

    // 清除按钮的样式
    textField.clearButtonMode=UITextFieldViewModeAlways;

    // 创建一个view
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(200, 200, 100, 100)];
    view.backgroundColor=[UIColor redColor];

    // 弹出一个自定义的视图,默认是键盘
    textField.inputView=view;

    // 给键盘添加一个辅助视图
    textField.inputAccessoryView=view;

    // 点击return回收键盘
    在.h中签订textField协议
    // 给textField设置代理人
    textField.delegate=self;

    return YES;
    }

// 实现协议方法
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
NSLog(@”测试return按钮”);
// 这句话是实现回收键盘的关键
[textField resignFirstResponder];
return YES;
}

  • (BOOL)textFieldShouldClear:(UITextField *)textField{
    NSLog(@”测试清除按钮”);
    return YES;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值