gpt4 book ai didi

iOS contentStretch 已弃用,如何拉伸(stretch)表格单元格?

转载 作者:行者123 更新时间:2023-11-28 21:54:08 25 4
gpt4 key购买 nike

我有一些较旧的 iOS 代码,其中包括从 UITableViewCell 派生的通用自定义 Composite Subview,它覆盖 setFrame 并使用 contentStretch 实现大小调整.这是一个通用的自定义 Table View Cell 类,我可以使用它在表格行 (UITableViewController) 中显示我想要的任何内容。

contentStretch 已被弃用一段时间 (iOS6),但我没有看到任何关于如何重写使用 contentStretch 的基于非图像的代码的信息。这是我现在拥有的:

- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];

[UIView setAnimationsEnabled:NO];
CGSize contentSize = cellContentView.bounds.size;
cellContentView.contentStretch = CGRectMake(225.0 / contentSize.width, 0.0, (contentSize.width - 260.0) / contentSize.width, 1.0);
[UIView setAnimationsEnabled:YES];
}

更新:

看来我可以摆脱我的 setFrame 覆盖,只需在我的 initWithStyle 中设置自动调整大小的掩码,如下所示:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
cellContentView = [[CompositeSubviewBasedResortCellContentView alloc] initWithFrame:CGRectInset(self.contentView.bounds, 0.0, 1.0) cell:self];
cellContentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
cellContentView.contentMode = UIViewContentModeRedraw;
[self.contentView addSubview:cellContentView];
}

return self;
}

最佳答案

您仍然可以使用自动调整大小蒙版

view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

如果将其粘贴进去,右键单击 UIViewAutoresizingFlexibleWidth 并单击“跳转到定义”,您将看到其他可用选项,从那里开始非常简单。

关于iOS contentStretch 已弃用,如何拉伸(stretch)表格单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27204771/

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