中心对齐的UITextfield在点击时将其占位符向左更改

时间:2017-10-31 10:20:47

标签: ios xcode storyboard

我在tableview单元格中对齐了UITextfields。 每当用户点击任何文本字段时,其占位符稍微向左移动。 我也附上了截图。请帮帮我。

In first picture, fusion id is moved towards left as its selected.

In second picture, password is moved towards left as its selected.

1 个答案:

答案 0 :(得分:1)

我将UITextField分类为:

[[],[],[],[]].reduce((acc, array) => acc + array.length, 0)
// returns 0

[[2, 3], [2, 3], [3, 5], [5, 6]].reduce((acc, array) => acc + array.length, 0)
// returns 8

然后在Interface Builder中将UITextField的类设置为 MyTextField

Set the Custom Class of the IB Object

以下是与UITextField相比的MyTextField行为的一些图像

Two placeholders behaving differently normal carat aligns to beginning of Placeholder which is also beginning UITexField centered carat aligns only to beginning of placeholder normal text entry aligns to beginning of UITextField "centred" text entry also aligns to beginning of MyTextField

这可能不是您想要的完整行为,但占位符不会“跳转”,如果需要,可以扩展此类技术以克服其他行为。