自定义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 ...
随机推荐
- 利用js闭包获取索引号
以tab选项卡效果为例: 网页中的选项卡效果
- PHP开发调试环境配置
——基于wamp和Eclipse for PHP Developers 引言 为了搭建PHP开发调试环境,我曾经在网上查阅了无数的资料,但没有一种真正能够行的通的.因为PHP开发环境需要很多种软件相互 ...
- [ReactiveCocoa]最简单的RAC入门操作
当knowckout.js出来的时候,确实被其kobinding惊艳了一下,等到AngularJS出来的时候,把MVVM的模式更是向前推进了一步.所以当ReactiveCocoa出来的时候,也很感兴趣 ...
- 在共享DLL中使用MFC 和在静态库中使用MFC的区别
使用VS2008,在项目属性中有一项MFC的使用,有三种设置: 1.使用标准Windows库 2.在共享DLL中使用MFC 3.在静态库中使用MFC 第一种顾名思义. ...
- 开源语音识别系统 Simon
http://www.lupaworld.com/proj.php?mod=view&cid=&id=824 语音识别系统 Simon:Simon 是一个开源的语音识别系统,它不仅可以 ...
- HttpHelps类,用来实现Http访问,Post或者Get方式的,直接访问,带Cookie的,带证书的等方式,可以设置代理
原文地址:http://blog.csdn.net/cdefg198/article/details/8315438 万能框架:http://www.sufeinet.com/forum.php?mo ...
- centos6.5 eclipse C/C++开发环境
- mysql数据库学习(一)--基础
一.简介 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好的 R ...
- OC运行时和方法机制笔记
在OC当中,属性是对字段的一种特殊封装手段. 在编译期,编译器会将对字段的访问替换为内存偏移量,实质是一种硬编码. 如果增加一个字段,那么对象的内存排布就会改变,需要重新编译才行. OC的做法是,把实 ...
- SQL整理4
--====================简单增删改===========--查看学生表的全部数据select * from studio --插入一个新的学生信息insert into stu ...