UITextField:前导截断
目前,我在 UITextField 中的文本在尾部被截断(例如“Hello,Wor...”)。我希望从前缘截断文本(例如“...lo,World!”)。
Currently, my text within a UITextField is truncating at the tail (eg. "Hello, Wor..."). I want the to truncate the text from the leading edge (eg. "...lo, World!").
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需更新文本属性(例如
defaultTextAttributes
)与.paragraphStyle
与lineBreakMode
of.byTruncatingHead
。不过,我不会仅仅替换
.paragraphStyle
。我会获取它,更新其lineBreakMode
,然后用它更新文本属性:这里是
.byTruncatingHead
、.byTruncatingMiddle
和 < code>.byTruncatingTail,分别为:You just have to update the text attributes (e.g.,
defaultTextAttributes
) with a.paragraphStyle
with alineBreakMode
of.byTruncatingHead
.I would not just replace the
.paragraphStyle
, though. I would fetch it, update itslineBreakMode
, and then update the text attributes with that:Here it is with
.byTruncatingHead
,.byTruncatingMiddle
and.byTruncatingTail
, respectively:我相信将
NSMutableParagraphStyle's lineBreakMode
与NSMutableAttributedString
一起使用可能会起作用这给出了类似这样的东西,这就是我认为你想要的:
I believe using
NSMutableParagraphStyle's lineBreakMode
withNSMutableAttributedString
might workThis gives something like this, which is what I think you want: