gpt4 book ai didi

ios - 如何使文本适合 UITableViewCell 是 iOS7?

转载 作者:行者123 更新时间:2023-11-29 02:41:42 28 4
gpt4 key购买 nike

我有一个 UILabelCell 但不知道如何使该标签中的所有文本适合(有时它会溢出)。关于如何在 iOS7 中调整文本大小的任何想法(所有解决方案都适用于以前的操作系统,它们不适用于 iOS7,因为这些方法已被弃用......)

这是制作单元格的代码:

if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.textLabel.text = text;}

最佳答案

我假设您的意思是允许文本溢出到多行?您可以使用 numberOfLines 属性,默认情况下为 1。

cell.textLabel.numberOfLines = 0;

0 表示行数不受限制。

需要注意的是,如果有太多行无法适应您使用的任何高度(或默认高度),您还需要在 tableView:heightForRowAtIndexPath: 中提供更高的高度。

关于ios - 如何使文本适合 UITableViewCell 是 iOS7?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25691976/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com