繼承UITextField重寫下面方法可實(shí)現(xiàn):
#import "QLCustomTextField.h"
@implementation QLCustomTextField
// 控制placeHolder的位置轧苫,左右縮20,但是光標(biāo)位置不變
/*
-(CGRect)placeholderRectForBounds:(CGRect)bounds
{
CGRect inset = CGRectMake(bounds.origin.x+100, bounds.origin.y, bounds.size.width -10, bounds.size.height);
return inset;
}
*/
// 修改文本展示區(qū)域祭刚,一般跟editingRectForBounds一起重寫
- (CGRect)textRectForBounds:(CGRect)bounds
{
CGRect inset = CGRectMake(bounds.origin.x+20, bounds.origin.y, bounds.size.width-25, bounds.size.height);//更好理解些
return inset;
}
// 重寫來(lái)編輯區(qū)域,可以改變光標(biāo)起始位置塌碌,以及光標(biāo)最右到什么地方惋耙,placeHolder的位置也會(huì)改變
-(CGRect)editingRectForBounds:(CGRect)bounds
{
CGRect inset = CGRectMake(bounds.origin.x+20, bounds.origin.y, bounds.size.width-25, bounds.size.height);//更好理解些
return inset;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end