//  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重写)的更多相关文章

  1. UITextField 的重写

    在很多产品设计的时候,产品设计人员设计出来的输入框总会要求,文字的内容距离做边框多少像素,编辑区域的其实点,距离左边多少像素,很多人绝的难以适应!其实这些都不存在很大的技术难度,一下这些方式都可以达到 ...

  2. FastAdmin Bootstrap-Table 自定义搜索的重写提示

    Bootstrap-Table 自定义搜索的重写提示 群友询问:这个搜索能自己写么? [群主]Karson-深圳(请勿@) "★找大神-山西 10:59:32 查看原文 [图片] 这个搜索能 ...

  3. Python中自定义类如果重写了__repr__方法为什么会影响到str的输出?

    这是因为Python3中,str的输出是调用类的实例方法__str__来输出,如果__str__方法没有重写,则自动继承object类的__str__方法,而object类的__str__方法是调用_ ...

  4. Yii2 GridView自定义链接之重写 ActionColumn

    最近刚开始用yii2,真是超棒的,但是也有许多不足的地方,今天要说的就是GridView链接问题.   <?= GridView::widget([ 'dataProvider' => $ ...

  5. Magento 自定义URL 地址重写 分类分级显示

    我们打算将URL在分类页面和产品页面分别定义为: domain.com/category/分类名.html domain.com/category/子分类名.html domain.com/goods ...

  6. java开发----自定义对象,重写equals方法

    javaweb开发中,用到了好多自定义对象,这时候如果不重写equals方法,很多时候都会返回false, 因此我们必须习惯重写这个方法. 重点: 1.equals比较俩对象时比较的是对象引用是否指向 ...

  7. 浅谈自定义UITextField的方法

    观察效果图 UITextField有以下几种特点: 1.默认占位文字是灰色的 2.当光标点上去时,占位文字变为白色 3.光标是白色的 接下来我们通过不同的方法来解决问题 一.将xib中的UITextF ...

  8. UIControl IOS控件编程 及UITextField的讲解

    第一部分 UIKit提供了一组控件:UISwitch开关.UIButton按钮.UISegmentedControl分段控件.UISlider滑块.UITextField文本字段控件.UIPageCo ...

  9. UITextField限制中英文字数和光标定位以及第三方输入限制问题

    先自定义一个UITextField的子类HLNavTextField,在控制器里调用子类的- (void)limitHansLength:(int)hans otherLength:(int)othe ...

  10. UITextField的常用属性,Delegate,重绘

        一  属性 UITextField * myTextField = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 200, 50 ...

随机推荐

  1. ThinkPHP 3.1 404页面的设置

    在很多网站中都会有使用404页面的时候,在ThinkPHP框架中该如何设置呢,接下来我介绍其中一种方法 1.首先要在Lib/Action 下建立EmptyAction.class.php模块内容如下: ...

  2. jsp九九乘法表

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  3. 解决 MySQL manager or server PID file could not be found! 的方法

    [root@centos var]# service mysqld stop MySQL manager or server PID file could not be found!       [F ...

  4. iOS中如何呼出另一个应用

    我们经常会遇到在一个应用里面呼出另一个应用的需求,比如在文档里面点击地址,调用safari来打开网页:比如在文件浏览器里面点击某种文件,自动激活一个应用来打开文件. iOS里面对于这样的需求使用URL ...

  5. ios 开发 常见问题解决 (持续更新)

    1.使用cocoaPods引用第三方类库,报错:file not found   . 解决方案:设置 Project->Info->Configurations之后  clear ,然后再 ...

  6. Jquery弹窗插件Lhgdialog的用法

    Lhgdialog的用法 大家都知道用js可以实现,但是在使用js实现的弹窗时得考虑很东西:浏览器的兼容.页面的交互等等问题. 在这里简单介绍一下lhgdialog的用法. 参数有: Title:弹窗 ...

  7. java实现xml文件增删改查

    java一次删除xml多个节点: 方案1.你直接改动了nodeList,这一般在做循环时是不同意直接这么做的. 你能够尝试在遍历一个list时,在循环体同一时候删除list里的内容,你会得到一个异常. ...

  8. Oracle基本代码学习

    /*------------Orcale函数----------------*/ 1.字符函数 LOWER()小写UPPER()大写INITCAP()把第一个字母大写CONCAT()字符串的连接(也可 ...

  9. 20151225--easyUI

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  10. “error LNK1169: 找到一个或多个多重定义的符号”的解决方法(转载)

    解决方案: “error LNK1169: 找到一个或多个多重定义的符号”的解决方法(转载) 遇到的问题: 在.h头文件中采用namespace 命名空间报错 test.h namespace LMR ...