自定义UITextField(UITextField重写)
// CustomField.h
#import <UIKit/UIKit.h>
@interface CustomField : UITextField
@end
// CustomField.m #import "CustomField.h" @implementation CustomField - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} /*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
*/
- (void)drawRect:(CGRect)rect
{
// Drawing code
} -(CGRect)clearButtonRectForBounds:(CGRect)bounds
{
return CGRectMake(bounds.origin.x +bounds.size.width - ,bounds.origin.y+bounds.size.height/-/, , );
}
//bounds.size.height -20
//控制placeHolder的位置,左右缩20
-(CGRect)placeholderRectForBounds:(CGRect)bounds
{
//return CGRectInset(bounds,20, 0);
CGRect inset= CGRectMake(bounds.origin.x+, bounds.origin.y+, bounds.size.width -, bounds.size.height);
return inset;
}
//控制显示文本的位置
-(CGRect)textRectForBounds:(CGRect)bounds
{
CGRect inset= CGRectMake(bounds.origin.x+, bounds.origin.y, bounds.size.width -, bounds.size.height);//更好理解些 return inset; }
//控制编辑文本的位置
-(CGRect)editingRectForBounds:(CGRect)bounds
{
//return CGRectInset(bounds, 10 , 0 ); CGRect inset= CGRectMake(bounds.origin.x +, bounds.origin.y, bounds.size.width -, bounds.size.height);
return inset;
}
//控制左视图位置
- (CGRect)leftViewRectForBounds:(CGRect)bounds
{
CGRect inset= CGRectMake(bounds.origin.x +, bounds.origin.y, bounds.size.width-, bounds.size.height);
return inset;
//returnCGRectInset(bounds,50,0);
} - (CGRect)rightViewRectForBounds:(CGRect)bounds;
{
CGRect inset= CGRectMake(bounds.origin.x +bounds.size.width-, bounds.origin.y+bounds.size.height/-,,);
return inset;
} //控制placeHolder的颜色、字体
- (void)drawPlaceholderInRect:(CGRect)rect
{
//CGContextRef context =UIGraphicsGetCurrentContext();
//CGContextSetFillColorWithColor(context,[UIColor yellowColor].CGColor);
[[UIColor brownColor] setFill]; [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:]]; }
@end // 使用方法,在XXXViewController里导入#import "CustomField.h" CustomField *myField=[[CustomField alloc]init];
自定义UITextField(UITextField重写)的更多相关文章
- UITextField 的重写
在很多产品设计的时候,产品设计人员设计出来的输入框总会要求,文字的内容距离做边框多少像素,编辑区域的其实点,距离左边多少像素,很多人绝的难以适应!其实这些都不存在很大的技术难度,一下这些方式都可以达到 ...
- FastAdmin Bootstrap-Table 自定义搜索的重写提示
Bootstrap-Table 自定义搜索的重写提示 群友询问:这个搜索能自己写么? [群主]Karson-深圳(请勿@) "★找大神-山西 10:59:32 查看原文 [图片] 这个搜索能 ...
- Python中自定义类如果重写了__repr__方法为什么会影响到str的输出?
这是因为Python3中,str的输出是调用类的实例方法__str__来输出,如果__str__方法没有重写,则自动继承object类的__str__方法,而object类的__str__方法是调用_ ...
- Yii2 GridView自定义链接之重写 ActionColumn
最近刚开始用yii2,真是超棒的,但是也有许多不足的地方,今天要说的就是GridView链接问题. <?= GridView::widget([ 'dataProvider' => $ ...
- Magento 自定义URL 地址重写 分类分级显示
我们打算将URL在分类页面和产品页面分别定义为: domain.com/category/分类名.html domain.com/category/子分类名.html domain.com/goods ...
- java开发----自定义对象,重写equals方法
javaweb开发中,用到了好多自定义对象,这时候如果不重写equals方法,很多时候都会返回false, 因此我们必须习惯重写这个方法. 重点: 1.equals比较俩对象时比较的是对象引用是否指向 ...
- 浅谈自定义UITextField的方法
观察效果图 UITextField有以下几种特点: 1.默认占位文字是灰色的 2.当光标点上去时,占位文字变为白色 3.光标是白色的 接下来我们通过不同的方法来解决问题 一.将xib中的UITextF ...
- UIControl IOS控件编程 及UITextField的讲解
第一部分 UIKit提供了一组控件:UISwitch开关.UIButton按钮.UISegmentedControl分段控件.UISlider滑块.UITextField文本字段控件.UIPageCo ...
- UITextField限制中英文字数和光标定位以及第三方输入限制问题
先自定义一个UITextField的子类HLNavTextField,在控制器里调用子类的- (void)limitHansLength:(int)hans otherLength:(int)othe ...
- UITextField的常用属性,Delegate,重绘
一 属性 UITextField * myTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 200, 50 ...
随机推荐
- IE9下Ajax缓存问题
使用jQuery的getJSON从后台定时获取数据并刷新界面,使用以下方法时,在Chrome,Firefox下没问题,但在IE9下却无法刷新数据 $.getJSON(webApp + "/G ...
- sql update小结
以前update用的不少,但都是简单的单表操作,没有在意,最近查阅多表关联更新及更新top n,发现update还真灵活,记录如下(在mssqlserver2008r2下测试通过): 1单表操作 u ...
- 重新理解一遍UpdatePanel
楼主只是想每天写点东西这样帮助自己的一个累积吧. 说明:楼主现在已经清楚了AJAX是怎么回事了,现在由于工作原因又摆弄起了UpdatePanel所以从AJAX的角度来分析一下UpdatePanel的使 ...
- VB MSFlexGrid 用法
http://blog.itpub.net/15453304/viewspace-445608/ 问题一,MSFlexGrid 点击一行,显示背景颜色,然后得到行号 首先,右键单击Msflexgrid ...
- jQuery 中使用 JSON
转载:http://www.cnblogs.com/haogj/archive/2011/12/01/2271098.html JSON 格式 json 是 Ajax 中使用频率最高的数据格式,在浏览 ...
- [问题解决] VNC连接黑屏或者灰屏+命令行
1.修改配置文件/root/.vnc/xstartup 注:有的系统配置里有 –nolisten tcp 和 –nohttpd ,这两个是阻止Xwindows登陆和HTTP方式VNC登陆的,如果需要图 ...
- Epipe
http://www.cnblogs.com/carekee/articles/2904603.html http://blog.chinaunix.net/uid-10716167-id-30805 ...
- MATLAB介绍
MATLAB MATLAB[1] 是美国MathWorks公司出品的商业数学软件,用于算法开发.数据可视化.数据分析以及数值计算的高级技术计算语言和交互式环境,主要包括MATLAB和Simulink ...
- c++学习笔记(c++中的引用)
1.c++中的bool类型: 其实c语言中也有bool类型,如果是遵守c90标准的编译器(其实现在大量编译器都是c90标准的),对于bool类型的使用除了要使用头文件 stdbool.h外,与 ...
- poj1503---大数加法
先讲一种错误的做法:WA了n次,大神一定帮我看一下//看到有说数组大小开到250,我改了之后还是不//思路是将arr这个数组的每一行附上输入的值,然后求每列所有数之和,当然进位 //maxlen记录这 ...