iOS学习UI之UITextfield

UITextField->UIControl->UIView

常用属性

1.图片对象转化为颜色对象

textField.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@”DOVE 1”]];

2.borderStyle 边框样式

textField.borderStyle = UITextBorderStyleNone;

3.contentVerticalAlignment 文本垂直方向

textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

4.adjustsFontSizeToFitWidth 自适应文字大小

textField.adjustsFontSizeToFitWidth = YES;

5.minimumFontSize 最小字体

textField.minimumFontSize = 18;

6.keyboardAppearance 键盘外观

textField.keyboardAppearance = UIKeyboardAppearanceDark;

7.keyboardType 键盘样式

textField.keyboardType = UIKeyboardTypeDefault;

8.textColor 文字颜色

textField.textColor = [UIColor purpleColor];

9.returnKeyType return键样式

textField.returnKeyType = UIReturnKeyGo;

10.autocapitalizationType 字母大写样式

textField.autocapitalizationType =UITextAutocapitalizationTypeAllCharacters;

11.autocorrectionType 自动纠错

textField.autocorrectionType = NO;

12.placeholder 提示文字

textField.placeholder = @”屠龙宝刀,点击就送”;

13.secureTextEntry 是否密文显示

textField.secureTextEntry = YES;

14.clearButtonMode 一键删除的模式

textField.clearButtonMode = UITextFieldViewModeWhileEditing;

15.clearsOnBeginEditing 再次编辑是否清空

textField.clearsOnBeginEditing = YES;

16.leftView 左视图

textField.leftView = view;

17.leftViewMode 左视图方式

textField.leftViewMode = UITextFieldViewModeAlways;

18.rightView 右视图

19.rightViewMode 右视图方式

20.inputAccessoryView 键盘上面的视图

21.inputView 键盘样式

22.textfield的代理

/**

* 输入框是否可以开始输入文字

*

* @param textField

*

* @return NO表示不能输入,YES表示可以输入

*/

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

NSLog(@”%s”,func);

return YES;

}// return NO to disallow editing.

/**

* 输入框开始响应就执行

*

* @param textField

*/

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

NSLog(@”%s”,func);

}// became first responder

//输入框是否可以结束输入文字

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{

// if (textField.text.length !=2) {

// return NO;

// }

NSLog(@”%s”,func);

return YES;

}// return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end

/**

* 输入框结束响应就执行

*

* @param textField

*/

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

NSLog(@”%s”,func);

}// may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called

//

/**

* 输入框文字出现变化就执行的方法

*

* @param textField

* @param range

* @param string

*

* @return

*/

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

NSLog(@"%ld    %ld",range.length,range.location);
NSLog(@"%@",string);
return YES;

}// return NO to not change text

/**

* 一键删除

*

* @param textField

*

* @return NO表示删除无效

*/

- (BOOL)textFieldShouldClear:(UITextField *)textField{

if ([textField.text isEqualToString:@”123”]) {

return NO;

}

NSLog(@”%s”,func);

return YES;

}// called when clear button pressed. return NO to ignore (no notifications)

/**

* textFieldShouldReturn

*

* @param textField 传入的键盘

*

* @return

*/

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

//收回键盘:光标消失 输入框失去第一响应

[textField resignFirstResponder];

NSLog(@”%s”,func);

return YES;

}// called when ‘return’ key pressed. return NO to ignore.

时间: 2024-07-30 14:41:37

iOS学习UI之UITextfield的相关文章

ios开发UI篇—UITextfield

概述 UITextField在界面中显示可编辑文本区域的对象. 您可以使用文本字段来使用屏幕键盘从用户收集基于文本的输入.键盘可以配置许多不同类型的输入,如纯文本,电子邮件,数字等等.文本字段使用目标操作机制和委托对象来报告在编辑过程中所做的更改. 除了基本的文本编辑行为之外,还可以将叠加视图添加到文本字段以显示其他信息并提供其他可定位控件.您可以为诸如书签按钮或搜索图标等元素添加自定义叠加视图.文本字段提供内置的叠加视图来清除当前文本.自定义覆盖视图的使用是可选的. 属性和方法 初始化 UIT

iOS开发-UI (五)UITextField

UITextField使用 1.创建方式 例: UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)]; 2.常用方法和属性 1)边框样式 @property(nonatomic)  UITextBorderStyle   borderStyle; UITextBorderStyleNone                       没有边框,背景默认为透明 UITextBorderS

iOS学习——UI相关小结

1 ? ? StoryBoard: 在Info.plist中可以查看Main storyboard,即入口storyboard,默认为main.storyboard,可以修改为自己创建的storyboard. 2 ? ? ViewController 每个viewController都绑定有一个类文件,程序执行时,会进入到绑定的类文件中执行其中的程序,在app中表现为一个界面.每新建一个viewController,都要新建一个对应的类(继承自UIViewController),并且在属性中绑定

iOS开篇——UI之UITextField

创建文本输入框 UITextField * textField = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 250, 40)]; 设置边框样式 textField.borderStyle = UITextBorderStyleRoundedRect; /* typedef NS_ENUM(NSInteger, UITextBorderStyle) { UITextBorderStyleNone, 无效果 UITextBorderS

【ios学习记录】- UITextField输入浮点数的限制

通常在编辑框中输入一些货品数量,金额时,我们都会做一些输入的判断限制.例如不能输入非法字符,只能输入数字等等.现把最近遇到的一些输入限制需求展现如下: 1. 输入小数位不能超过两位: 2. 不能重复输入小数点: 3. 不能输入除数字以外的字符(但不包括退格键,负号键): 4. 限制长度为最小为1,最大为11. 为了实现以上需求,主要是依靠以下UITextFieldDelegate的一个协议方法来实现的: - (BOOL)textField:(UITextField *)textField sho

学习IOS开发UI篇--UI知识点总结(一) UIButton/UITextField

UIkit框架下的几个基本控件,UIButton,UITextField,UILabel,UIImageView,UIScrollView,UITableView,UITableViewCell,UIPageControl; 他们的继承关系,UILabel,UIImageView,UIScrollView,UITableViewCell,直接继承自UIView; UIButton,UITextField,UIPageControl,继承自UIControl; UIControl继承自UIView

学习IOS开发UI篇--UI知识点总结(四) UITabelView/UITableViewCell

UITabelView:常用属性 @property (nonatomic)          CGFloat    rowHeight;             // will return the default value if unset @property (nonatomic)          CGFloat     sectionHeaderHeight;   // will return the default value if unset @property (nonatom

学习IOS开发UI篇--UI知识点总结(三) UIScrollView/UIPageControl/NSTimer

UIScrollView:常用属性 @property(nonatomic)   UIEdgeInsets     contentInset;               // default UIEdgeInsetsZero. add additional scroll area around content @property(nonatomic,getter=isPagingEnabled) BOOL   pagingEnabled;     // default NO. if YES,

学习IOS开发UI篇--UITableView/数据模型嵌套/UITableViewCell/Cell的重用

1.UITableView ================================================== UITableView有两种格式:group和plain 2.UITableView如何展示数据 ================================================== UITableView需要一个数据源(dataSource)来显示数据 凡是遵守UITableViewDataSource协议的OC对象,都可以是UITableView的