UItextField
2015-08-26 16:26
357 查看
UItextField相关代码如下:
- (UITextField *)textField { if (_textField == nil) { _textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 300, 40)]; _textField.layer.borderColor = [[UIColor lightGrayColor] CGColor]; _textField.layer.borderWidth = 0.5; _textField.layer.cornerRadius = 3; _textField.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)]; _textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; _textField.leftViewMode = UITextFieldViewModeAlways; _textField.clearButtonMode = UITextFieldViewModeWhileEditing; _textField.font = [UIFont systemFontOfSize:15.0]; _textField.backgroundColor = [UIColor whiteColor]; _textField.placeholder = @"hello word!"; _textField.returnKeyType = UIReturnKeyDone; _textField.delegate = self; } return _textField; }
- (void)creatUItextField{ UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(120.0f, 80.0f, 150.0f, 30.0f)]; [textField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型 textField.placeholder = @"默认显示的字"; //默认显示的字 textField.secureTextEntry = YES; //密码 textField.autocorrectionType = UITextAutocorrectionTypeNo; textField.autocapitalizationType = UITextAutocapitalizationTypeNone; textField.returnKeyType = UIReturnKeyDone; textField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X textField.delegate = self; UITextField *iptext = [[UITextField alloc]initWithFrame:CGRectMake(45, 435, 300, 45)]; [iptext setBackgroundColor:[UIColor whiteColor]]; [iptext setKeyboardType:UIKeyboardTypeNumberPad]; [iptext setTextAlignment:NSTextAlignmentCenter]; [iptext setUserInteractionEnabled:NO]; [iptext setPlaceholder:@"输入正确服务器地址"]; [iptext setDelegate:self]; [iptext.layer setBorderColor:[UIColor blackColor].CGColor]; [iptext.layer setBorderWidth:1]; } //从其他地方退出键盘 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.textview resignFirstResponder]; } //当你按下键盘上的retun键时 - (BOOL)textFieldShouldReturn:(UITextField *)textField{ [self.numTF resignFirstResponder]; return YES; } //当行输入文本框将要开始编辑时 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ return YES; } //当输入文本开始进入编辑时 - (void)textFieldDidBeginEditing:(UITextField *)textField{ } //将要完成编辑时 - (BOOL)textFieldShouldEndEditing:(UITextField *)textField{ return YES; } //已经退出模式时 - (void)textFieldDidEndEditing:(UITextField *)textField{ NSLog(@"%@",textField.text); }
//键盘弹出与隐藏 - (void)viewWillAppear:(BOOL)animated{ [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboarHidd) name:UIKeyboardWillHideNotification object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboarShow) name:UIKeyboardWillShowNotification object:nil]; } - (void)keyboarHidd{ [UIView animateWithDuration:0.1 animations:^{ self.loginView.frame = CGRectMake(BOUND_WIDTH/3.5, 100, BOUND_WIDTH/2.3, BOUND_HEIGHT - 120); }]; } - (void)keyboarShow{ [UIView animateWithDuration:0.1 animations:^{ CGRect frame= self.loginView.frame; frame.origin.y -= 160; self.loginView.frame = frame; }]; }
- (void)viewDidLoad { [super viewDidLoad]; //监听软键盘 事件 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(WillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil]; } #pragma mark - keyboard -(void)WillChangeFrame:(NSNotification *)notif{ NSDictionary *info = [notif userInfo]; NSValue *value = [info objectForKey:UIKeyboardFrameEndUserInfoKey]; CGSize keyboardSize = [value CGRectValue].size; //收起软键盘的时候 if (value.CGRectValue.origin.y>400) { [UIView animateWithDuration:.2 animations:^{ self.toolbar.frame = CGRectMake(0, self.view.bounds.size.height-45, 320, 45); }]; } else { //弹出软键盘的时候 [UIView animateWithDuration:.2 animations:^{ CGRect frame = self.toolbar.frame; frame.origin.y = self.view.bounds.size.height - keyboardSize.height - self.toolbar.bounds.size.height; self.toolbar.frame = frame; }]; } }
相关文章推荐
- Android UI设计:ExpandableListView
- POJ 2479 Maximum sum && 2593 Max Sequence (dp)买一送一
- UISwitch
- 详细解析BluetoothAdapter的详细api
- 循环结构中break、continue、return和exit的区别
- easyui panel自适应问题
- BLToolkit : Table-value functions
- Android UI设计:Gallery
- UIStepper
- 72.UITableView:改变 TableHeaderView 的高度
- Office 365 IT Professional ——配置Anonymous Guest Links
- 二分+树状数组/线段树(区间更新) HDOJ 4339 Query
- easyui 绑定数据
- Jesque 基础入门
- Builder
- 不要随便使用 runAllManagedModulesForAllRequests="true" 来解决问题
- iPhone开发之UIScrollView滚动组件的使用(一) 拖线实现——大图的移动展示
- 力矩< torque>详解
- Arduino以太网盾
- Builder Pattern