UITextField使用的一些细节
UITextField使用的一些细节

这篇博文是我自己使用UITextField的一些总结,并没有太多营养,并会持续更新。
2014.9.15
--------------------------------------------------------------------------------------------------------------------------------------
源码:
//
// RootViewController.m
// UITextField
//
// Created by YouXianMing on 14-9-15.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "RootViewController.h" @interface RootViewController ()<UITextFieldDelegate> @property (nonatomic, strong) UITextField *textField; @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; _textField = [[UITextField alloc] initWithFrame:CGRectMake(, , , )];
_textField.layer.borderWidth = .f;
_textField.layer.borderColor = [UIColor redColor].CGColor;
_textField.backgroundColor = [UIColor whiteColor];
_textField.textAlignment = kCTTextAlignmentLeft; // 左对齐
_textField.delegate = self ;
_textField.keyboardType = UIKeyboardTypeNumberPad; // 数字键盘
_textField.placeholder = @"请输入4位验证码";
_textField.clearsOnBeginEditing = YES; // 空出左侧边缘空隙(通过添加一个view来实现)
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(, , ,
CGRectGetHeight(_textField.bounds))];
_textField.leftView = view;
_textField.leftViewMode = UITextFieldViewModeAlways; [self.view addSubview:_textField]; // 添加手势
[self addGesture];
} - (void)addGesture
{
// 手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
[self.view addGestureRecognizer:tap];
} // 限制输入长度
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (range.location >= )
{
return NO;
}
else
{
return YES;
}
} - (void)tapGesture:(UITapGestureRecognizer *)tap
{
// 取消第一响应状态
[_textField resignFirstResponder];
} @end
效果:

左侧空出空隙

限制输入长度

--------------------------------------------------------------------------------------------------------------------------------------
UITextField使用的一些细节的更多相关文章
- UITextField
UITextFieldDemo 效果 特点 1.有效定制键盘的样式 2.处理键盘对文本框的遮挡 用法 1.导入文件(UITextField+CreateInputAccessoryView.h/.m) ...
- iOS开发笔记7:Text、UI交互细节、两个动画效果等
Text主要总结UILabel.UITextField.UITextView.UIMenuController以及UIWebView/WKWebView相关的一些问题. UI细节主要总结界面交互开发中 ...
- swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...
- UILabel,UITextField 以及UIButton应用
</pre><pre name="code" class="cpp">一.UILabel 它是ioS开发使用的控件来显示文本,它是UIV ...
- iOS基础 - UIDatePicker and UIPickerView and UITextField
1.UIDatePicker继承自UIControl,因此不会通过代理来监听事件的改变,而是通过addTarget来监听事件.监听的事件是值改变事件. 2.UIPickerView继承自UIView, ...
- iOS基础 - UITextField
一.UITextField 1.常见属性 @property(nonatomic,retain) UIView *leftView; // 设置文本框左边显示什么控件,可以让文本框的内容往右边挪动 @ ...
- iOS 之 UITextField
UITextField 相关细节处理: 1. 设置leftView , rightView let leftView = UIView() // 设置leftView/rightView之后,勿忘设 ...
- Vue.js 和 MVVM 小细节
MVVM 是Model-View-ViewModel 的缩写,它是一种基于前端开发的架构模式,其核心是提供对View 和 ViewModel 的双向数据绑定,这使得ViewModel 的状态改变可以自 ...
- vue2.0实践的一些细节
最近用vue2.0做了个活动.做完了回头发现,好像并没有太多的技术难点,而自己好像又做了比较久...只能说效率有待提升啊...简单总结了一些比较细节的点. 1.对于一些已知肯定会有数据的模块,先用一个 ...
随机推荐
- WPF样式动画Trigger.EnterActions和Trigger.ExitActions(ExitActions其实可以不做任何事情)
这是一个鼠标移入后,控件往左移动的动画: <Style TargetType="{x:Type StackPanel}"> <Setter Property=&q ...
- vim shortcut
1.vim ~/.vimrc 进入配置文件 如果不知道vimrc文件在哪,可使用 :scriptnames 来查看 set nu #行号 set tabstop=4 #一个tab为4个空格长度 set ...
- 把AspDotNetCoreMvc程序运行在Docker上-part4:实现负载均衡
在上一part<把AspDotNetCoreMvc程序运行在Docker上-part3:使用独立的存储容器>,我们利用MySql容器和Volume实现了真正意义上的数据存储.整个结构非常简 ...
- C语言——打印“Hello World!”,这么简单?
打印Hello World! #inculde <stdio.h> int main(){ printf("Hello World!"); return 0; } 第一 ...
- IOS第三方之SVProgressHUD
这个第三方和MBProgressHUD差不多,也挺简单的. // // ViewController.m // ProgressHUD // // Created by City--Online on ...
- mysql replace语句
语法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 REPLACE [LOW_PRIORITY | DELAYED] [INTO] tbl_name [ ...
- C# 从Excel 批量导入数据库
最近遇到了关于 C# MVC 批量添加数据的问题,解决后就自己写了一个未完成的小Demo 不管什么编程语言都会提供操作Excel文件的方式,C#操作Excel主要有以下几种方式: 1.Excel 说 ...
- .net core iis 502.5
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>n ...
- 比较json和fastjson的put()
首先,分别运行下面两段json和fastjson的代码: import org.json.JSONException; import org.json.JSONObject; public class ...
- jackson @ResponseBody 处理日期类型的字段
前言:以前只知道一种方式(@JsonFormat)来处理日期格式问题,今天才发现还有两种方式,并且可以全局设置格式,这里记录一下. 首先,pom.xml 中需要先引入如下 jackson 的依赖: & ...