UITextView 末尾的省略号
如果我有多行不可滚动的 UITextView,其文本长度超过了可见区域的容纳范围,那么文本就会像这样被截断:
Congress shall make no law respecting
an establishment of religion, or
如何让文本在文本截断位置处显示省略号,像这样
Congress shall make no law respecting
an establishment of religion, or …
其他控件(如标签和按钮)也具有此功能。
If I have multi-line non-scrollable UITextView whose text is longer than can fit in the visible area, then the text just cuts off like so:
Congress shall make no law respecting
an establishment of religion, or
How would I get the text to show with an ellipsis where the text cut-off is, like so
Congress shall make no law respecting
an establishment of religion, or …
Other controls like labels and buttons have this ability.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不使用
UILabel
将numberOfLines
设置为适当的值并免费获得该功能?Why not use a
UILabel
settingnumberOfLines
to something appropriate and getting that functionality for free?UITextView
设计为当字符串大于视图可以显示的内容时滚动。确保您已在代码或 xib 中正确设置锚定和自动调整大小属性。这是 博客文章。
The
UITextView
is designed to scroll when the string is larger than what the view can show. Make sure that you have set the anchoring and autoresize attributes correctly in code or your xib.Here is an example from a blog post about how to implement your own ellipsis.
有人刚刚向我展示,在 iOS 7 及更高版本上使用 UITextView 做到这一点实际上非常容易:
Someone just showed me that it's actually really easy to do this with UITextView on iOS 7 and up: