我在使用xib添加UITextField
控件的时候发现输入框在输入文字时会上下浮动 , 导致文字下半部分被遮挡了 . 百度了许多解决方案 , 什么设置frame
, 重写 -(CGRect)borderRectForBounds:(CGRect)bounds
并不能解决问题 .
-
方案一
在代码里面直接设置textField
的clearButtonMode
属性;
self.nameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
-
方案二
在storyboard
上和xib
上设置方式:
把 UITextField
的 Clear Button
属性设置成 Appears while editing
;
如图:

-
方案三
我们使用UITextField
时是不需要设置它的约束height
,默认的高度为17
(14号字体时,不同字体不同高度),但是这时输入文字时会导致下半部分被遮挡,所以我们在这种情况下应该设置它的约束height
,我建议设置高度为默认高度 +4
在storyboard
上和xib
上设置如图:

网友评论