iOS(学习3) UITextField 常用属性

来源:互联网 发布:抢票的软件 编辑:程序博客网 时间:2024/06/04 01:02
#import “ViewController.h"//设置代理@interface ViewController ()<UITextFieldDelegate>{    UITextField *textField;    UIButton *_button;}@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    //背景设置成白色    self.view.backgroundColor = [UIColor yellowColor];        //textField 在视图中的位置    textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 30, 300, 30)];    //设置边框样式 有圆角 白色背景    textField.borderStyle = UITextBorderStyleRoundedRect;        //背景颜色    //textField.backgroundColor = [UIColor blueColor];        //提示文字    textField.placeholder = @"请输入密码";        //设置密文输入    textField.secureTextEntry = YES;        //设置键盘样式    textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;        //键盘风格  半透明    /*     UIKeyboardAppearanceLight  //不透明     UIKeyboardAppearanceAlert  //半透明     */    textField.keyboardAppearance = UIKeyboardAppearanceAlert;        //设置弹出视图 比如自定义键盘    UIImageView *imageVeiw = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"11.jpg"]] ;    imageVeiw.frame = CGRectMake(100, 10, 320, 220);    //textField.inputView = imageVeiw;        //左视图  .jpg格式 要带后缀名   png格式不用带后缀名    textField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"图片名字"]];    /*     UITextFieldViewModeUnlessEditing //编辑是消失     UITextFieldViewModeAlways   //从不消失     */    textField.leftViewMode = UITextFieldViewModeAlways;        //清除按钮格式    textField.clearButtonMode = UITextFieldViewModeAlways;    //再次编辑时 是否清空    textField.clearsOnBeginEditing = YES;        //内容对齐方式    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;        //文本对齐方式    textField.textAlignment = NSTextAlignmentCenter;        //滚动    textField.adjustsFontSizeToFitWidth = NO;        //设置最小字号    textField.minimumFontSize = 20;        //设置return健样式    textField.returnKeyType = UIReturnKeyGoogle;       textField.delegate = self;        UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, 300, 30)];        [self.view addSubview:textField2];    [self.view addSubview:textField];            _button = [UIButton buttonWithType:UIButtonTypeCustom];    _button.frame = CGRectMake(10, 450, 300, 30);    [_button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];    _button.backgroundColor = [UIColor whiteColor];    [self.view addSubview:_button];        }//按钮点击方法- (void) buttonClick{    NSLog(@"haha");}- (void)keybarldWillShow{    [UIView animateWithDuration:0.20 animations:^{        _button.frame = CGRectMake(10, 250, 300, 30);    }];}- (void)keybarldWillHhow{    [UIView animateWithDuration:0.20 animations:^{        _button.frame = CGRectMake(10, 450, 300, 30);    }];}//点击屏幕收缩键盘- (void)controlAction{    [textField resignFirstResponder];}//文本输入框是否可以进入编辑模式- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{    NSLog(@"文本输入框是否可以进入编辑模式");    return YES;}//文本输入框已经进入编辑模式- (void)textFieldDidBeginEditing:(UITextField *)textField{    NSLog(@"文本输入框已经进入编辑模式");}//文本输入框是否可以退出编辑模式- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{    NSLog(@"文本输入框是否可以退出编辑模式");    return YES;}//文本输入框已经退出编辑模式- (void)textFieldDidEndEditing:(UITextField *)textField{    NSLog(@"文本输入框已经退出编辑模式");}//文本输入框是否点击Retur按钮- (BOOL)textFieldShouldReturn:(UITextField *)textField{    [textField resignFirstResponder];    NSLog(@"文本输入框是否点击Retur按钮");    return YES;}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

0 0
原创粉丝点击