动态配置 UITableViewCell 文本
这是我的问题:我有 UITableView,我想使用不同的文本字体动态配置“THE Cell”文本,例如第一行将是 12,Helvetica,粗体,第二行将是 10,Helvetica。另请注意,行数未知,需要动态确定。任何帮助表示赞赏!
ps:显然问题没有被很好地理解。我并不是想在不同的单元格中显示每一行。因此,仅考虑一个单元格并为该特定单元格配置文本。我有一个动态确定的该单元格的行数,因此它可能是 2 或 3,具体取决于信息的可用性。我希望这些线条有不同的字体和不同的颜色。一种方法是为单元格提供动态数量的 UILabel,但我想看看是否还有其他选项?
Here is my problem: I have UITableView and I want to dynamically configure "THE Cell" text with different text fonts e.g. first line will be 12, Helvetica, Bold and the second line will be 10, Helvetica. Also note that number of lines is unknown and needs to be dynamically determined. Any help appreciated!
ps: Apparently question isn't understood well. I didn't mean to show each line in different cells. So think about only one cell and configuring the text for this particular cell. I have a dynamically determined number of lines for this cell so it could be 2 or 3 depending on the availability of the information. And I want this lines to have different fonts and different colors. One way to go for this is to have dynamic number of UILabel for the cell, but I would like to see if there is other options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有示例模式,我无法很好地回答这个问题,但情况如下:
在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
中添加您的自定义设置。以下是一些示例:1)
2)
3)
除非您有特定的模式,否则如果您不知道有多少行,这可能会很困难。如果您需要更多帮助,请在下面评论。
I can't really answer this very well without an example pattern but here it goes:
In
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
add your customisations. Here's some examples:1)
2)
3)
Unless you have a specific pattern, it can be hard if you don't know how many rows there are. If you need any more help just comment below.
这是相当简单的事情。只需设置单元格的内容
即可根据单元格的
indexPath
调整字体大小、颜色等。如果您想要大量示例来了解所有可能的情况,请查看 Apple 的 表视图编程指南。
This is fairly trivial to do. Just set the content of the cells in
You can adjust the font size, color, etc based on the
indexPath
of the cell.If you want a plethora of examples of what all is possible, then check out Apple's Table View Programming Guide.