使用 UITableView 和 UILabel 的聊天类型视图
我想做的是创建一个看起来评论部分的聊天类型。
我从带有自定义单元格的 UITableView 开始。我在里面放了一个 UILabel 。
要求是我需要与实际评论文本不同的用户名颜色。
现在,如果我使用 2 个不同的标签,以确保 textColor 差异,则注释文本会缩进,因为其标签在 userName 标签完成后开始。 我希望评论文本在进入第二行时从单元格的开头开始,就像在大多数聊天应用程序中一样。
以及如何解决这个问题的想法?
What I want to do is create a chat type looking comment-section.
I have started with a UITableView with custom cells. And I have put a UILabel inside it.
The requirement is that I need a different color of the userName, from the actual comment text.
Now if I use 2 different labels, to ensure the textColor difference, then the comment text gets indented, as its label starts after the userName label finishes.
I want the comment text to start from the starting of the cell when it goes into 2nd line, like it is in most chat apps.
And ideas how to go around it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确的话,你能做的就是使用 2 个标签,一个在另一个标签之上。用户名标签位于较大的 commentText 标签之上。
commentText 标签的实际文本将是附加到 userName 标签文本的 commentText。
这样做的结果是,userName 标签将完全覆盖 commentText 标签中 userName 所在的区域。用户名的颜色看起来与评论文本的颜色不同。
If I am understanding it correctly, what you can do is use 2 labels, 1 top of another. UserName label being on top of the bigger commentText label.
The actual text of the commentText label will be the commentText appended to the text of userName label.
What that will do is, the userName label will exactly cover the area of the commentText label where the userName is there. And the userName will look like having a different color from the commentText.