UITextField

@interface ViewController ()<UITextFieldDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    //创建UITextField
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(120, 120, 300, 30)];
    textField.center = self.view.center;

    //设置背景颜色
//    textField.backgroundColor = [UIColor grayColor];
    //设置边框样式
//    textField.borderStyle = UITextBorderStyleRoundedRect;
    /**
     *  
     UITextBorderStyleNone,无边框
     UITextBorderStyleLine ,有边框
     UITextBorderStyleBezel,有边框和阴影
     UITextBorderStyleRoundedRect,圆角
     */
    //设置背景图片
    textField.background = [UIImage imageNamed:@"voice_reply"];

    //提示文字
    textField.placeholder = @"用户名";
    //设置和读取文本内容
    textField.text = @"Hello World";
    //设置字体
    [textField setFont:[UIFont fontWithName:@"黑体" size:17]];
    NSLog(@"%@",[UIFont familyNames]);

    //密文输入
    textField.secureTextEntry = YES;
    //键盘类型
    //数字键盘
    textField.keyboardType = UIKeyboardTypeDefault;
    //默认键盘
//    textField.keyboardType = UIKeyboardTypeDefault;

    //键盘风格
    textField.keyboardAppearance = UIKeyboardAppearanceDark;

    UITextField *cv = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
    cv.backgroundColor = [UIColor redColor];

    cv.inputView = cv;
    //设置系统键盘或者自定义键盘上的视图
    cv.inputAccessoryView = cv;

    cv.delegate = self;



    //设置左右视图
    textField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fengwo_head_icon"]];
    textField.leftViewMode = UITextFieldViewModeAlways;
    //设置清除按钮显示模式
    textField.clearButtonMode = UITextFieldViewModeAlways;
    //再次编辑时是否清空之前的内容,默认NO
    textField.clearsOnBeginEditing = YES;
    //对齐方式
    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
    textField.font = [UIFont systemFontOfSize:30];
    //
    textField.adjustsFontSizeToFitWidth = YES;
    //设置return键
    textField.returnKeyType = UIReturnKeySearch;
    //设置输入自动纠正模式
    /**
     *  
     UITextAutocapitalizationTypeNone,
     UITextAutocapitalizationTypeWords,
     UITextAutocapitalizationTypeSentences,
     UITextAutocapitalizationTypeAllCharacters,
     */
    textField.autocapitalizationType = UITextAutocapitalizationTypeWords;




//    [self.view addSubview:cv];
    [self.view addSubview:textField];



}
-(BOOL)textFieldShouldClear:(UITextField *)textField{
    NSLog(@"%s",__func__);
    return YES;
}
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    NSLog(@"%s",__func__);
    return YES;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    NSLog(@"%s",__func__);
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    NSLog(@"%s",__func__);
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    NSLog(@"should");
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{

    NSLog(@"%s",__func__);
}
- (void)textFieldDidEndEditing:(UITextField *)textField{

    NSLog(@"%s",__func__);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值