iOS,文本输入,键盘相关
6.UITextField和UITableView自定义下拉列表框
7.使用UIPickerView在UITextField实现滚动选择
8.使用UIDatePicker在UITextField实现日期选择
UIKeyboard键盘相关知识点
一、键盘风格
UIKit框架支持8种风格键盘。
typedef enum {
UIKeyboardTypeDefault, // 默认键盘:支持所有字符
UIKeyboardTypeASCIICapable, // 支持ASCII的默认键盘
UIKeyboardTypeNumbersAndPunctuation, // 标准电话键盘,支持+*#等符号
UIKeyboardTypeURL, // URL键盘,有.com按钮;只支持URL字符
UIKeyboardTypeNumberPad, //数字键盘
UIKeyboardTypePhonePad, // 电话键盘
UIKeyboardTypeNamePhonePad, // 电话键盘,也支持输入人名字
UIKeyboardTypeEmailAddress, // 用于输入电子邮件地址的键盘
} UIKeyboardType;
用法用例:textView.keyboardtype = UIKeyboardTypeNumberPad;
二、键盘外观
typedef enum {
UIKeyboardAppearanceDefault, // 默认外观:浅灰色
UIKeyboardAppearanceAlert, //深灰/石墨色
} UIKeyboardAppearance;
用法用例:textView.keyboardAppearance=UIKeyboardAppearanceDefault;
三、回车键
typedef enum {
UIReturnKeyDefault, //默认:灰色按钮,标有Return
UIReturnKeyGo, //标有Go的蓝色按钮
UIReturnKeyGoogle, //标有Google的蓝色按钮,用于搜索
UIReturnKeyJoin, //标有Join的蓝色按钮
UIReturnKeyNext, //标有Next的蓝色按钮
UIReturnKeyRoute, //标有Route的蓝色按钮
UIReturnKeySearch, //标有Search的蓝色按钮
UIReturnKeySend, //标有Send的蓝色按钮
UIReturnKeyYahoo, //标有Yahoo!的蓝色按钮,用于搜索
UIReturnKeyDone, //标有Done的蓝色按钮
UIReturnKeyEmergencyCall, //紧急呼叫按钮
} UIReturnKeyType;
用法用例:textView.returnKeyType=UIReturnKeyGo;
四、自动大写
typedef enum {
UITextAutocapitalizationTypeNone, //不自动大写
UITextAutocapitalizationTypeWords, //单词首字母大写
UITextAutocapitalizationTypeSentences, //句子首字母大写
UITextAutocapitalizationTypeAllCharacters, //所有字母大写
} UITextAutocapitalizationType;
用法用例:textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
五、自动更正
typedef enum {
UITextAutocorrectionTypeDefault,//默认
UITextAutocorrectionTypeNo,//不自动更正
UITextAutocorrectionTypeYes,//自动更正
} UITextAutocorrectionType;
用法用例:textField.autocorrectionType = UITextAutocorrectionTypeYes;
六、安全文本输入
textView.secureTextEntry=YES;
开启安全输入主要是用于密码或一些私人数据的输入,此时会禁用自动更正和自此缓存。
//点击回车键的回调
UITextFieldDelegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
return YES;
}
点击空白区域隐藏键盘(UIKeyboard)
//结束触摸
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//isExclusiveTouch一个布尔值来指示接收机处理触摸事件。
//没有触摸_textUser进入if内操作
if (![_textUser isExclusiveTouch]) {
//resignFirstResponder取消第一响应者状态的。如果对textfield使用的话,那么调用这个方法,textfield的第一响应者状态就会取消,然后键盘就消失了。
[_textUser resignFirstResponder];
}
}
或者
//结束触摸
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];//收回键盘
}
键盘(UIKeyboard)挡住输入框处理
//需要处理输入框被键盘挡住的.h文件,遵守UITextFieldDelegate协议
#import <UIKit/UIKit.h>
#import "MyKeyboard.h"
@interface Test2ViewController : UIViewController<MykeyBoardDelegate,UITextFieldDelegate>
@end
//需要处理输入框被键盘挡住的.m文件,实现UITextFieldDelegate协议方法
//实现委托
_textUser.tag=1;
_textUser.delegate=self;
_textPwd.tag=2;
_textPwd.delegate=self;
//选中开始编辑文本框内容
-(void)textFieldDidBeginEditing:(UITextField *)textField{
_textTag=textField.tag;
//根据tag判断这个键盘是否是被遮住的键盘
if (_textTag==2) {
//将界面上移避免文本框被键盘挡住
CGRect frame = self.view.frame;
frame.origin.y -=200;
frame.size.height +=200;
self.view.frame = frame;
}
}
//结束编辑文本框内容
-(void)textFieldDidEndEditing:(UITextField *)textField{
//根据tag判断这个键盘是否是被遮住的键盘
if (_textTag==2) {
CGRect frame=self.view.frame;
frame.origin.y+=200;
frame.size.height-=200;
self.view.frame=frame;
}
}
自定义键盘(UIKeyboard)
//MyKeyboard.h文件(自定义键盘)
#import <UIKit/UIKit.h>
@protocol MykeyBoardDelegate<NSObject>
//文本框值输入委托
-(void)myKeyBoardInput:(NSString *)inputString;
//删除文本框字委托
-(void)myKeyBoardBack;
//隐藏键盘委托
-(void)myKeyBoardOK;
@end
@interface MyKeyboard : UIView
@property (nonatomic,weak) id<MykeyBoardDelegate> delegate;//声明一个委托变量
@end
#import "MyKeyboard.h"
@implementation MyKeyboard
-(id)initWithFrame:(CGRect)frame{
self=[super initWithFrame:frame];
if (self) {
self.bounds=CGRectMake(0, 0, frame.size.width, frame.size.height);
UIButton *buttonX=[[UIButton alloc] initWithFrame:CGRectMake(frame.size.width*0.8, 0, frame.size.width*0.19, frame.size.height*0.24)];
[buttonX.layer setCornerRadius:2.0];
[buttonX.layer setBorderWidth:0.5];
[buttonX setBackgroundColor:[UIColor whiteColor]];
[buttonX setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[buttonX setTitle:@"X" forState:UIControlStateNormal];
[buttonX addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:buttonX];
//第四横排键盘
UIButton *button0=[[UIButton alloc] initWithFrame:CGRectMake(frame.size.width*0.2, frame.size.height*0.75, frame.size.width*0.19, frame.size.height*0.24)];
[button0.layer setCornerRadius:2.0];
[button0.layer setBorderWidth:0.5];
[button0 setBackgroundColor:[UIColor whiteColor]];
[button0 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button0 setTitle:@"0" forState:UIControlStateNormal];
[button0 addTarget:self action:@selector(inputAction:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button0];
UIButton *buttonPoint=[[UIButton alloc] initWithFrame:CGRectMake(frame.size.width*0.4, frame.size.height*0.75, frame.size.width*0.19, frame.size.height*0.24)];
[buttonPoint.layer setCornerRadius:2.0];
[buttonPoint.layer setBorderWidth:0.5];
[buttonPoint setBackgroundColor:[UIColor whiteColor]];
[buttonPoint setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[buttonPoint setTitle:@"." forState:UIControlStateNormal];
[buttonPoint addTarget:self action:@selector(inputAction:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:buttonPoint];
UIButton *buttonOK=[[UIButton alloc] initWithFrame:CGRectMake(frame.size.width*0.6, frame.size.height*0.75, frame.size.width*0.19, frame.size.height*0.24)];
[buttonOK.layer setCornerRadius:2.0];
[buttonOK.layer setBorderWidth:0.5];
[buttonOK setBackgroundColor:[UIColor whiteColor]];
[buttonOK setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[buttonOK setTitle:@"确定" forState:UIControlStateNormal];
[buttonOK addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:buttonOK];
}
return self;
}
-(void)inputAction:(UIButton *)sender{
[self.delegate myKeyBoardInput:[sender currentTitle]];
}
-(void)backAction:(UIButton *)sender{
if ([[sender currentTitle] isEqualToString:@"确定"]) {
[self.delegate myKeyBoardOK];
}else if ([[sender currentTitle] isEqualToString:@"X"]){
[self.delegate myKeyBoardBack];
}
}
@end
//Test2ViewController.h文件,需要用到自定义软件盘的文本框
#import <UIKit/UIKit.h>
#import "MyKeyboard.h"
@interface Test2ViewController : UIViewController<MykeyBoardDelegate,UITextFieldDelegate>
@end
//Test2ViewController.m文件,需要用到自定义软件盘的文本框
//初始化自定义键盘
MyKeyboard *myKboard=[[MyKeyboard alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height*0.3)];
//引用自定义键盘
_textUser.inputView=myKboard;
//委托
myKboard.delegate=self;
//键盘输入实现
-(void)myKeyBoardInput:(NSString *)inputString{
//点击的是用户名文本框时
if (_textTag==1) {
self.textUser.text=[self.textUser.textstringByAppendingString:inputString];
}else if(_textTag==2){
self.textPwd.text=[self.textPwd.textstringByAppendingString:inputString];
}
}
//键盘删除实现
-(void)myKeyBoardBack{
if (_textTag==1) {
if (self.textUser.text.length>0) {
self.textUser.text=[self.textUser.textsubstringToIndex:self.textUser.text.length-1];
}
}else if (_textTag==2){
if (self.textPwd.text.length>0) {
self.textPwd.text=[self.textPwd.textsubstringToIndex:self.textPwd.text.length-1];
}
}
}
//隐藏键盘实现
-(void)myKeyBoardOK{
if (_textTag==1) {
[_textUser resignFirstResponder];
}else if (_textTag==2){
[_textPwd resignFirstResponder];
}
}
监听键盘弹出或消失消息
//键盘弹出
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardChanged:) name:UIKeyboardWillChangeFrameNotification object:nil];
//键盘消失
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
//监听键盘弹出方法
-(void)keyBoardChanged:(NSNotification *)notification{
//UIKeyboardFrameEndUserInfoKey 将要变化的大小
CGRect keyBoardRect=[notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
keyBoardHeight=keyBoardRect.size.height;//获取弹出键盘高度
//键盘弹出时间
NSTimeInterval time=[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//下面可以做文本输入框坐标改变动画,与键盘弹出耗费时间一致(体验比较好)
[UIView animateWithDuration:time animations:^{
//self.view.frame=changeFrame;
}];
}
//监听键盘消失方法
-(void)keyBoardWillHide:(NSNotification *)notification{
//键盘弹出时间
NSTimeInterval time=[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//下面可以做文本输入框坐标改变动画,与键盘弹出耗费时间一致(体验比较好)
[UIView animateWithDuration:time animations:^{
//self.view.frame=changeFrame;
}];
}
UITextField和UITableView自定义下拉列表框
效果图:
//DownboxViewController.h文件
#import <UIKit/UIKit.h>
#import "CommboxView.h"
@interface DownboxViewController : UIViewController
@property (nonatomic,strong) CommboxView *cbView;
@
//DownboxViewController.m文件
#import "DownboxViewController.h"
@interface DownboxViewController ()
@end
@implementation DownboxViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
//1、创建视图
CGFloat yyX = 40;
CGFloat yyY = 40;
CGFloat yyW = self.view.frame.size.width-80;
CGFloat yyH = 100;
CommboxView *yy = [[CommboxView alloc] initWithFrame:CGRectMake(yyX, yyY, yyW, yyH)];
//2、完成布局
[self.view addSubview:yy];
//3、赋值成员变量
self.cbView = yy;
self.cbView.textField.placeholder=@"请选择";
//设置数据
self.cbView.tbArray=[[NSArray alloc] initWithObjects:@"风继续吹",@"真的爱你",@"透明的你",@"爱的太迟",@"Dear friends",@"永远不回头", nil];
}
//结束触摸时,隐藏下拉列表框
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
//isExclusiveTouch一个布尔值来指示接收机处理触摸事件。
//没有触摸_textUser进入if内操作
if (![self.cbView.textField isExclusiveTouch]) {
//resignFirstResponder取消第一响应者状态的。如果对textfield使用的话,那么调用这个方法,textfield的第一响应者状态就会取消,然后键盘就消失了。
[self.cbView.textField resignFirstResponder];
self.cbView.tbView.hidden=YES;
//设置右边view
self.cbView.textField.rightView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_textfield_more@2x.png"]];
}
}
@end
//CommboxView.h文件
#import <UIKit/UIKit.h>
@interface CommboxView : UIView<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>
@property (nonatomic,strong) UITableView *tbView;//用作显示下拉列表框
@property (nonatomic,strong) NSArray *tbArray;//用作下拉列表框的数据
@property (nonatomic,strong) UITextField *textField;//文本框
@end
//CommboxView.m文件
#import "CommboxView.h"
@implementation CommboxView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if ( self )
{
//1、创建视图
CGFloat yyX = 0;
CGFloat yyY = 0;
CGFloat yyW = frame.size.width;
CGFloat yyH = frame.size.height/2.5;
UITextField *uiText=[[UITextField alloc] initWithFrame:CGRectMake(yyX, yyY, yyW, yyH)];
[uiText.layer setCornerRadius:5.0 ];
[uiText.layer setBorderWidth:1.0];
//完成布局
[self addSubview:uiText];
uiText.delegate=self;
//设置右边view
uiText.rightView=[[UIImageView alloc] initWithImage:[UIImageimageNamed:@"login_textfield_more@2x.png"]];
//设置右边样式总是显示
uiText.rightViewMode = UITextFieldViewModeAlways;
//赋值成员变量
self.textField=uiText;
//创建视图
UITableView *uiTable=[[UITableView alloc] initWithFrame:CGRectMake(yyX, yyH, yyW, frame.size.height-yyY)];
uiTable.backgroundColor=[UIColor grayColor];
//分割线颜色
uiTable.separatorColor=[UIColor lightGrayColor];
[uiTable.layer setCornerRadius:5.0];
//完成布局
[self addSubview:uiTable];
uiTable.dataSource=self;
uiTable.delegate=self;
uiTable.hidden=YES;
//赋值成员变量
self.tbView=uiTable;
}
return self;
}
//选中单元格操作
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
self.textField.text=[_tbArray objectAtIndex:indexPath.row];
[self.textField resignFirstResponder];
self.tbView.hidden=YES;
//设置右边view
self.textField.rightView=[[UIImageView alloc] initWithImage:[UIImageimageNamed:@"login_textfield_more@2x.png"]];
}
//开始编辑文本框时将下拉列表显示
-(void)textFieldDidBeginEditing:(UITextField *)textField{
//取消第一响应者状态,可以到达无焦点,不弹出键盘的效果
[self.textField resignFirstResponder];
self.tbView.hidden=NO;
//设置右边view
self.textField.rightView=[[UIImageView alloc] initWithImage:[UIImageimageNamed:@"login_textfield_more_flip@2x.png"]];
}
//设置单元格宽度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
return self.textField.frame.size.height*0.8;
}
//每个分区多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.tbArray.count;
}
//设置单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellDo=@"cellDo";
UITableViewCell *cell=(UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellDo];
if (!cell) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellDo];
}
[[cell textLabel] setText:[_tbArray objectAtIndex:indexPath.row]];
cell.backgroundColor=[UIColor grayColor];
return cell;
}
@end
使用UIPickerView在UITextField实现滚动选择
//
// PickerTestViewController.m
//
//
// Created by Vie on 15/10/12.
//
//
#import "PickerTestViewController.h"
@interface PickerTestViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property(nonatomic,strong)UIPickerView *pickerView;
@property(nonatomic,strong)UITextField *txField;
@property(nonatomic,strong)NSMutableArray *yearArray,*monthArray,*dayArray;
@end
@implementation PickerTestViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
self.yearArray=[[NSMutableArray alloc] initWithObjects:@"2013",@"2014",@"2015", nil];
self.monthArray=[[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
self.dayArray=[[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8", nil];
self.pickerView=[[UIPickerView alloc] init];
self.pickerView.dataSource=self;
self.pickerView.delegate=self;
self.txField=[[UITextField alloc] initWithFrame:CGRectMake(self.view.frame.size.width*0.1f, 100, self.view.frame.size.width*0.8f, 44)];
self.txField.layer.borderWidth=1.0f;
self.txField.layer.cornerRadius=5.0f;
[self.view addSubview:self.txField];
//设置输入框的弹出视图为UIPickerView
self.txField.inputView=self.pickerView;
}
//用户选中某个row时,对应改变文本
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
[self setTxFieldText];
}
//结束文本框触摸时隐藏UIPickerView
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if (![self.txField isExclusiveTouch]) {
[self.txField resignFirstResponder];
[self setTxFieldText];
}
}
//将文本框的内容设置为滚动表格选中值
-(void)setTxFieldText{
self.txField.text=[NSString stringWithFormat:@"%@-%@-%@",[self.yearArrayobjectAtIndex:[self.pickerView selectedRowInComponent:0]],[self.monthArrayobjectAtIndex:[self.pickerView selectedRowInComponent:1]],[self.dayArrayobjectAtIndex:[self.pickerView selectedRowInComponent:2]]];
}
//指定UIPickerView上的文本
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
NSString *str;
if (component==0) {
str=[self.yearArray objectAtIndex:row];
}else if (component==1){
str=[self.monthArray objectAtIndex:row];
}else{
str=[self.dayArray objectAtIndex:row];
}
return str;
}
//返回每个轮最大的行数。
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
if (component==0) {
return self.yearArray.count;
}else if (component==1){
return self.monthArray.count;
}else{
return self.dayArray.count;
}
}
//返回一个整数,表示列数
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 3;
}
@end
使用UIDatePicker在UITextField实现日期选择
//
// DatePickerViewController.h
//
//
// Created by Vie on 15/10/12.
//
//
#import <UIKit/UIKit.h>
@interface DatePickerViewController : UIViewController
@end
//
// DatePickerViewController.m
//
//
// Created by Vie on 15/10/12.
//
//
#import "DatePickerViewController.h"
@interface DatePickerViewController ()
@property(nonatomic,strong)UITextField *txField;
@property(nonatomic,strong)UIDatePicker *datePicker;
@end
@implementation DatePickerViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor whiteColor]];
self.txField=[[UITextField alloc] initWithFrame:CGRectMake(self.view.frame.size.width*0.1f, 100, self.view.frame.size.width*0.8f, 44)];
self.txField.layer.borderWidth=1.0f;
self.txField.layer.cornerRadius=5.0f;
self.txField.placeholder=@"选择日期";
[self.view addSubview:self.txField];
self.datePicker=[[UIDatePicker alloc] init];
//设置日期选取器模式
self.datePicker.datePickerMode=UIDatePickerModeDate;
//默认根据手机本地设置来显示为中文还是其他语言
NSLocale *locale=[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];//设置为中文显示
self.datePicker.locale=locale;
//设置日期范围
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"yyyy-MM-dd"];
NSDate *minDate= [dateFormatter dateFromString:@"1970-01-01"];
NSDate *maxDate=[dateFormatter dateFromString:@"2030-12-31"];
self.datePicker.minimumDate=minDate;
self.datePicker.maximumDate=maxDate;
//设置响应时间
[self.datePicker addTarget:self action:@selector(pickerValueChanged) forControlEvents:UIControlEventValueChanged];
[self.txField setInputView:self.datePicker];
}
//结束文本框触摸时隐藏UIPickerView
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if (![self.txField isExclusiveTouch]) {
[self.txField resignFirstResponder];
[self setTxFieldText];
}
}
//选择器改变时,对应改变文本框内容
-(void)pickerValueChanged{
[self setTxFieldText];
}
//设置文本框内容
-(void)setTxFieldText{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"yyyy-MM-dd"];
NSString *dateString=[dateFormatter stringFromDate:self.datePicker.date];
self.txField.text=dateString;
}
@end
设置文本输入框样式
//图片验证码输入
self.imgLable=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, telLableWidth, telLableHeight)];
self.imgLable.text=@"验证码";
self.imgLable.textColor=[UIColor blackColor];
self.imgLable.numberOfLines=0;
self.imgLable.textAlignment=NSTextAlignmentCenter;
self.imgLable.font=[UIFont fontWithName:@"Arial" size:18.0f];
UIView *imgBgView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 95, 40)];
self.codeImgView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 38)];
self.codeImgView.center=imgBgView.center;
self.codeImgView.backgroundColor=[UIColor grayColor];
[imgBgView addSubview:self.codeImgView];
float imgCodeFielY=statusHeight+navHeight+30+self.telLable.frame.size.height;
self.imgCodeField=[[UITextField alloc] initWithFrame:CGRectMake(0, imgCodeFielY, telFieldWidth, telLableHeight)];
self.imgCodeField.placeholder=@"输入图片验证码";
[self.imgCodeField setBorderStyle:UITextBorderStyleRoundedRect];
//设置输入框左边视图
self.imgCodeField.leftView=self.imgLable;
self.imgCodeField.leftViewMode=UITextFieldViewModeAlways;
//设置输入框右边视图
self.imgCodeField.rightView=imgBgView;
self.imgCodeField.rightViewMode=UITextFieldViewModeAlways;
self.imgCodeField.tag=102;
self.imgCodeField.delegate=self;
self.imgCodeField.keyboardType=UIKeyboardTypeEmailAddress;
[self.view addSubview:self.imgCodeField];
实现带文本输入的UIAlertView弹窗
UIAlertView *alerView=[[UIAlertView alloc] initWithTitle:@"请输入账户密码" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[alerView setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
UITextField *accountField=[alerView textFieldAtIndex:0];
accountField.placeholder=@"请输入账户";
UITextField *pwdField=[alerView textFieldAtIndex:1];
pwdField.placeholder=@"请输入密码";
[alerView show];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"账号:%@;密码:%@",[alertView textFieldAtIndex:0].text,[alertView textFieldAtIndex:1].text);
}
iOS,文本输入,键盘相关的更多相关文章
- iOS系列 基础篇 08 文本与键盘
iOS系列 基础篇 08 文本与键盘 目录: 1. 扯扯犊子 2. TextField 3. TextView 4. 键盘的打开和关闭 5. 打开/关闭键盘的通知 6. 键盘的种类 7. 最后再扯两句 ...
- 最全的Swift社交应用文本输入优化汇总
在大部分应用中,都有输入的需求,面对众多用户,他们的想法各异,输入的文本内容也是千奇百怪,面对不同的输入,我们该如何优化输入体验?本文将汇总一下Swift社交应用文本输入优化技巧. AD: 一.输入相 ...
- 【PyQt5-Qt Designer】QLineEdit 文本输入
QLineEdit 文本输入 一.QlineEdit 基本方法 setAlignment() 按固定值方式对齐文本 Qt.AlignLeft:水平方向靠左对齐 Qt.AlignRight:水平方向靠右 ...
- Xamarin iOS教程之键盘的使用和设置
Xamarin iOS教程之键盘的使用和设置 Xamarin iOS使用键盘 在文本框和文本视图中可以看到,当用户在触摸这些视图后,就会弹出键盘.本节将主要讲解键盘的输入类型定义.显示键盘时改变输入视 ...
- ios下虚拟键盘出现"搜索"字样
最近在开发过程中,发现用户输入想要检索的内容,弹出虚拟键盘,在安卓机上虚拟键盘最右下角会有‘搜索’字样,而ios上虚拟键盘最右下角只有‘换行’字样, 这样用户体验就会大打折扣. 安卓机上虚拟键盘 io ...
- Word Flow:创造吉尼斯世界纪录的触屏文本输入的全新体验——微软Windows Phone 8.1系统倾情巨献
Flow:创造吉尼斯世界纪录的触屏文本输入的全新体验--微软Windows Phone 8.1系统倾情巨献" title="Word Flow:创造吉尼斯世界纪录的触屏文本输入的全 ...
- iOS textField输入金额的限制,小数点前9位,后面两位
iOS textField输入金额的限制,小数点前9位,后面两位,如果不加小数点,最大位数是9位,加上小数点,最大位数是12位,超出最大位数可删除 - (BOOL)textField:(UITextF ...
- IOS TextField伴随键盘移动
这篇文章介绍的是一个简单而又实用的小方法. 我想对于登陆时的一些效果大家应该都不会陌生. 今天就介绍一下,当开始输入TextField文本时键盘弹出TextField伴随键盘移动的实现. 先看一下演示 ...
- iOS TextView输入长度限制 设置placeholder
textView在使用中通常会有2个功能是最常用的 设置placeholder 限制输入长度 TYLimitedTextView刚好是为了解决这个2个问题而诞生的,下面讲解TYLimitedTextV ...
随机推荐
- 【BZOJ】2823: [AHOI2012]信号塔
题意 给\(n\)个点,求一个能覆盖所有点的面积最小的圆.(\(n \le 50000\)) 分析 随机增量法 题解 理论上\(O(n^3)\)暴力,实际上加上随机化后期望是\(O(n)\)的. 算法 ...
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery
题目链接 线段树的逆过程,想了老一会,然后发现应该是包含区间对存在有影响,就不知怎么做了...然后尚大神,说,So easy,你要倒着来,然后再正着来,判断是不是合法就行了.然后我乱写了写,就过了.数 ...
- JAVA_用Java来获取访问者真实的IP地址
在jsp里,获取客户端的ip地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的.但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实I ...
- 19.创建如下三个类:(People类中的三个方法分别输出一些信息,ChinaPeople 和AmericanPeople类重写父类的三个方法)。
package zuoye2; public class People { protected double height; protected double weight; private Stri ...
- Python 3.x下消除print()自动换行
Python 2.x下的print语句在输出字符串之后会默认换行,如果不希望换行,只要在语句最后加一个“,”即可.但是在Python 3.x下,print()变成内置函数,加“,”的老方法就行不通了. ...
- apache中.htaccess不起作用
找到apache的配置文件httpd.conf文件,找到: 代码如下 复制代码 #LoadModule rewrite_module modules/mod_rewrite.so 去掉前面的#号. ...
- C#面向对象整理
一.里氏转换 (1)子类可以赋值给父类:如果有一个地方需要一个父类作为参数,我们可以给一个子类代替. (2)如果父类装的是子类对象,那么这个父类可以强转为子类对象. 二.值类型跟引用类型区别 1.在内 ...
- HTTP协议 (六) 状态码详解
HTTP协议 (六) 状态码详解 HTTP状态码,我都是现查现用. 我以前记得几个常用的状态码,比如200,302,304,404, 503. 一般来说我也只需要了解这些常用的状态码就可以了. 如果 ...
- 手动创建oem
[oracle@std bin]$ /u02/app/product//db_1/bin/emca -config dbcontrol db -repos create STARTED EMCA at ...
- C++对析构函数的误解(转)
C++析构前言 析构函数在什么时候会自动被调用,在什么时候需要手动来调用,真不好意思说偶学过C++…今日特此拨乱反正. C++析构误解正文 对象在构造的时候系统会分配内存资源,对一些数据成员进行初始化 ...