UITextField知识点总结(一)

//文本框的属性
//账号框
//1.创建对象

_userField = [[UITextField alloc]initWithFrame:CGRectMake(10, 0, 150, 30)];

//2.设置中心点

_userField.center = CGPointMake(160, 50);

//3.背景颜色

_userField.backgroundColor = [UIColor grayColor];

//4.边框样式 系统样式

_userField.borderStyle = UITextBorderStyleRoundedRect;

//显示键盘的地方显示表情视图

// _userField.inputView = [self createEmotionView];

//5.显示

[self.view addSubview:_userField];

//6.键盘弹回

_userField.delegate = self;

//密码框
//1.创建对象

_passField = [[UITextField alloc]initWithFrame:CGRectMake(10, 0, 150, 30)];

//2.设置中心点

_passField.center = CGPointMake(160, 100);

//3.背景颜色

_passField.backgroundColor = [UIColor grayColor];

//4.边框样式 系统样式
“`
_passField.borderStyle = UITextBorderStyleRoundedRect;
(
textField.keyboardType = UIKeyboardTypeNumberPad;//数字键UIKeyboardTypeDefault, // 当前键盘(默认) UIKeyboardTypeASCIICapable, // 字母输入键 UIKeyboardTypeNumbersAndPunctuation, //数字和符号 UIKeyboardTypeURL, URL键盘 UIKeyboardTypeNumberPad, 数字键盘
UIKeyboardTypePhonePad, 电话号码输入键盘 UIKeyboardTypeEmailAddress, //邮件地址输入键盘
} UIKeyboardType;
10.键盘风格
textView.keyboardAppearance=UIKeyboardAppearanceDefault; UIKeyboardAppearanceDefault, 默认外观,浅灰色 UIKeyboardAppearanceAlert, 深灰 石墨色

)
    //5.显示
    ```
    [self.view addSubview:_passField];
    ```
    //6.键盘弹回
    ```
    _passField.delegate = self;
    ```
    //7.设置安全输入
    ```
    _passField.secureTextEntry = YES;
    ```
    //8.显示数字键盘
    ```
    _passField.keyboardType = UIKeyboardTypeNumberPad;
    ```
    //9.给数字键盘添加键盘弹回的按钮
    //9.1 添加 附件(附加)视图
    //创建一个UIImageView
    //注意:设置附件视图的frame:x,y,wigth都不用管,只要将高度值设置好就行
    ```
    UIImageView *backView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
    backView.userInteractionEnabled = YES;
    backView.image = [UIImage imageNamed:@"back"];
    _passField.inputAccessoryView = backView;//注意:不要忘记添加
//加入一个按钮
```
UIButton *keyBoardBack = [UIButton newButtonWithFrame:CGRectMake(10, 0, 120, 40) type:UIButtonTypeSystem title:@"键盘弹回" center:CGPointMake(100, 20) target:self andAction:@selector(keyBoardBack:)];
[backView addSubview:keyBoardBack];
//清空输入框
UIButton *cleanField = [UIButton newButtonWithFrame:CGRectMake(10, 0, 120, 40) type:UIButtonTypeSystem title:@"清空输入框" center:CGPointMake(200, 20) target:self andAction:@selector(cleanField:)];

[backView addSubview:cleanField];

```
//10.输入视图 键盘就是放在输入视图上面
//将账号输入框对应的键盘变成表情视图
//作用:自定义键盘
```
_userField.inputView = [self createEmotionView];
```
//11.添加背景图片
//注意:如果想自己添加背景图片,输入框的样式不能是UITextBorderStyleRoundedRect
//重新设置边框样式
```
_userField.borderStyle = UITextBorderStyleLine;
_userField.background = [UIImage imageNamed:@"back"];
```
//12.关闭大写提示
```
_userField.autocapitalizationType = UITextAutocapitalizationTypeNone;
```
//13.关闭纠错提示
```
_userField.autocorrectionType = UITextAutocorrectionTypeNo;
```
//14.设置输入前的提示文字
```
_userField.placeholder = @"请输入账号";
```
//15.添加擦出按钮
```
//UITextFieldViewModeAlways 总显示
_userField.clearButtonMode = UITextFieldViewModeAlways;
```
//16.在没有输入文字的时候键盘的return键不可以使用
```
_userField.enablesReturnKeyAutomatically = YES;
```
//17.自动调节文字的大小,以适应输入框的宽度
```
_userField.adjustsFontSizeToFitWidth = YES;
```
//文字可以自适应的最小尺寸
```
_userField.minimumFontSize = 5;
```
//18.输入的文字
```
_userField.text = @" ";
```
//19.添加左边的视图
```

// UILabel *nameLabel = [UILabel newLabelWithFrame:CGRectMake(0, 0, 60, 30) alignment:NSTextAlignmentLeft title:@”用户名:” andFont:10];
// nameLabel.backgroundColor = [UIColor redColor];

    //将一个图像视图添加成左视图
    ```
    UIImageView *leftImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"head8_100x100"];
    _userField.leftView = leftImageView;
    ```
    //设置显示模式
    ```
    _userField.leftViewMode = UITextFieldViewModeAlways;
    ```
    //20.添加右视图
    //注意:一个对象不能同时添加成左视图和右视图
    ```
    UIImageView *rightImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
    rightImageView.image = [UIImage imageNamed:@"head8_100x100"];

    _userField.rightView = rightImageView;
    _userField.rightViewMode = UITextFieldViewModeAlways;
    ```
    //21.竖直方向显示位置
    ```
    UITextField *tempField = [[UITextField alloc]initWithFrame:CGRectMake(10, 100, 240, 100)];
    tempField.borderStyle = UITextBorderStyleLine;
    [self.view addSubview:tempField];
    ```
    //在竖直方向显示在底端
    ```
    tempField.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
    ```
    //22.设置水平方向位置
    ```
    tempField.textAlignment = NSTextAlignmentRight;
    // Do any additional setup after loading the view, typically from a nib.
    ```
//23.编辑内容时垂直对齐方式

text2.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
“`
//24.

text2.adjustsFontSizeToFitWidth = YES;

//默认是NO YES当充满边框时,文字会缩小,当小到⼀一定程度时仍然会滚动;自适应宽度;

text2.minimumFontSize = 20;

//设置滚动时最小字号(与滚动相关)(前提:要比设置的字体小,否则没有意义

//24.设置return键

  text2.returnKeyType = UIReturnKeyGoogle;search typedef enum
  ```
   {      UIReturnKeyDefault, 默认 灰色按钮,标有Return     UIReturnKeyGo,      标有Go的蓝色按钮      UIReturnKeyGoogle,标有Google的蓝色按钮,用语搜索     UIReturnKeyJoin,标有Join的蓝色按钮     UIReturnKeyNext,标有Next的蓝色按钮     UIReturnKeyRoute,标有Route的蓝色按钮     UIReturnKeySearch,标有Search的蓝色按钮     UIReturnKeySend,标有Send的蓝色按钮     UIReturnKeyYahoo,标有Yahoo的蓝色按钮     UIReturnKeyYahoo,标有Yahoo的蓝色按钮     UIReturnKeyEmergencyCall, 紧急呼叫按钮  } UIReturnKeyType; 

25. 首字母是否大写      text2.autocapitalizationType  =  UITextAutocapitalizationTypeAllCharacters;//所有字母大写 typedef enum {      UITextAutocapitalizationTypeNone, 不自动大写      UITextAutocapitalizationTypeWords,  单词首字母大写      UITextAutocapitalizationTypeSentences,  句子的首字母大写     UITextAutocapitalizationTypeAllCharacters, 所有字母都大写  } UITextAutocapitalizationType; 
20. 
    //系统的单例使用
    ```
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setInteger:2 forKey:@"myint"];
    int a = [defaults integerForKey:@"myint"];
}

pragma mark //获取创建的表情键盘

“`
-(UIView *)createEmotionView
{
UIView *myEmotionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 160)];
myEmotionView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.5];

//CTRL+CMD+SPACE

NSArray *buttonTitleArray = [NSArray arrayWithObjects:@"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值