如何在表格视图行中写入两个或多个文本并以不同的方式放置它们?
我有一个 UITableView,我想右对齐一行中应该右对齐的文本和应该左对齐的另一个文本。这两个文本都应该从行边框的一些空格开始。我不希望它们从行的边框开始。我怎样才能做到这一点?
我想在每一行中写入左对齐的文本以及右对齐的文本。
提前致谢。
I have a UITableView and i want to right a text in a row which should be right aligned and another text which should be left aligned. And both of those texts should start with some space from border of the row. I don't want them to start with the border of the row. How can i do that?
I want to write text in every row which is left aligned and also a text which is right alighned.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的 cellForRowAtIndexPath 方法中,只需创建一个具有 2 个 UILabels 的单元格,并为它们提供所需的位置。小例子:
附近没有SDK,所以可能会出现一些错误。
希望有帮助
In your cellForRowAtIndexPath method just create a cell with 2 UILabels and give them the desired location. Small example:
did it without SDK nearby, so there might be some mistakes.
Hope it helps
UILabel 在样式和布局方面非常有限。考虑使用多种布局或 CoreText。
UILabel is very limited in terms of styling and layout. Considering either using multiple layouts or CoreText.
您可以做的是对标签进行子类化并重写其drawtextinrect函数,这样
您就可以在标签边缘周围留出边距
您还可以创建一个包含 2 个自定义标签的 uiview,并相应地左右对齐它们。使用 uvview 作为 2 个标签的容器,根据需要放置它们。我认为这可以创建您正在寻找编辑的效果
:刚刚看到您的编辑是针对表格单元格的。您需要创建一个自定义单元格以及自定义 uilabel
what you could do is subclass the label and over write its drawtextinrect function like so
this would allow you to give a margin around the edges of the label
also you could create a uiview that contains 2 of this custom labels and left and right align them accordingly. using the uvview as a container for the 2 labels to position them as needed. i reckon that could create the effect you looking for
edit: just seen your edit was for table cell. you would need to create a custom cell as well as custom uilabel