我无法加载视图中的所有文本

发布于 2024-12-18 03:41:40 字数 1448 浏览 3 评论 0原文

在我的应用程序中,我很少有带有较长文本的视图。 在我的详细视图中,我已从数据库导入文本,对于一些短文本,它可以工作,但对于更长的文本,它会给我带来问题。当我采用较小的字体时,它会显示所有文本,因此它可以从数据库加载它,但会产生其他一些问题。 我那部分的代码是:

case RestaurantItemTypeDescription : {
            cell = [tableView dequeueReusableCellWithIdentifier:@"Restaurant Description"];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Restaurant Description"];
            }
            cell.imageView.image = nil;

            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            CGRect rectLabel = CGRectMake(cell.frame.origin.x+20, cell.frame.origin.y+10, cell.frame.size.width-20, cell.frame.size.height-20);
            UILabel* label = [[UILabel alloc] initWithFrame:rectLabel];

            label.lineBreakMode = UILineBreakModeWordWrap;
            label.numberOfLines = 0;
            label.font = [UIFont fontWithName:@"Helvetica" size:13.0]; //Same font used for calculating height
            label.text = item.itemText;
            label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
            [cell addSubview:label];
//          [label release];
            //NSLog(@"description=%@", item.itemText);
            cell.accessoryType = UITableViewCellAccessoryNone;
            break;
        }

我有自动调整大小属性,但它似乎不起作用。

有人可以告诉我该怎么做吗?我在网上搜索,似乎对视图中的文本大小没有限制。 谢谢...

In my application I have few views with longer text.
In my detail view I have been imported text from database and for some short texts it works but for longer it make me problem. When I take smaller font it shows me all text so it loads it from database good but make some other problem.
My code for that part is:

case RestaurantItemTypeDescription : {
            cell = [tableView dequeueReusableCellWithIdentifier:@"Restaurant Description"];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Restaurant Description"];
            }
            cell.imageView.image = nil;

            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            CGRect rectLabel = CGRectMake(cell.frame.origin.x+20, cell.frame.origin.y+10, cell.frame.size.width-20, cell.frame.size.height-20);
            UILabel* label = [[UILabel alloc] initWithFrame:rectLabel];

            label.lineBreakMode = UILineBreakModeWordWrap;
            label.numberOfLines = 0;
            label.font = [UIFont fontWithName:@"Helvetica" size:13.0]; //Same font used for calculating height
            label.text = item.itemText;
            label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
            [cell addSubview:label];
//          [label release];
            //NSLog(@"description=%@", item.itemText);
            cell.accessoryType = UITableViewCellAccessoryNone;
            break;
        }

I have autoresize atribute but it seams it doesn't work.

Can someone please tell me what to do? I was searching the web and it seams that there is no restriction about size of text in view.
Thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦亿 2024-12-25 03:41:40

您需要调整标签的高度和单元格的高度以适应较长的文本。

此处有一个关于如何执行此操作的不错的指南。

You'll need to adjust the height of the label AND the height of the cell to account for the longer text.

There's a decent guide on how to do it here.

§对你不离不弃 2024-12-25 03:41:40

Autoresize 属性仅用于在视图大小更改时调整大小,例如当方向从纵向更改为横向或调用 setFrame 时:

您需要调整 UILabel 的大小以使标签足够大以显示所有文本。为此,您必须计算 UILabel 必须有多大。 这个问题涵盖了执行此操作的各种选项。

Autoresize attribute is only used to resize when the size of the view is changed like when the orientation changes from portrait to landscape or when you invoke setFrame:

You need to resize the UILabel to make the label large enough to show all the text. To do that you have to calculate how big the UILabel must be. This question covers various options for doing that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文