方法1
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
方法2
//繼承UITextField 重寫方法
- (CGRect)textRectForBounds:(CGRect)bounds
{
return CGRectInset(bounds, 2, 1);
}
- (CGRect)editingRectForBounds:(CGRect)bounds
{
return CGRectInset(bounds, 2, 1);
}
方法3
//如果文字尺寸不高碱璃,顯示區(qū)域足夠大悍抑,UITextField就可以正常顯示。
//當UITextField不能完全顯示漢字的時候皇忿,就會變成可滾動,文字就會低于中心線,點擊刪除按鈕的時候笤喳,看起來就會向下偏移辜妓。
//使用NSLOG輸出UITextField的layoutSubviews方法枯途,顯示UITextEditor的contentOffset發(fā)生了偏移忌怎。
//因此重寫layoutSuviews方法,在[super layoutSubview]之后重置UITextEditor的contentOffset.y 就可以了酪夷。
- (void)layoutSubviews
{
[super layoutSubviews];
for (UIScrollView *view in self.subviews)
{
if ([view isKindOfClass:[UIScrollView class]])
{
CGPoint offset = view.contentOffset;
if (offset.y != 0)
{
offset.y = 0;
view.contentOffset = offset;
}
break;
}
}
參考了下面三個帖子
帖子1--stackoverflow
帖子2--stackoverflow
帖子3--cocoachina