gpt4 book ai didi

ios - initWithStyle 上的 UITableViewCell 宽度 :reuseIdentifier:

转载 作者:行者123 更新时间:2023-11-29 04:50:20 26 4
gpt4 key购买 nike

我创建了一个自定义 UITableViewCell,其中包含 2 个标签。一个应该有固定的宽度,而另一个应该向右扩展,只要有空间即可。

我正在创建这样的 UILabels:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
codeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 60, 20)];
[self.contentView addSubview:codeLabel];
[codeLabel release];

nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(76, 4, self.frame.size.width - 100, 34)];
[self.contentView addSubview:nameLabel];
[nameLabel release];
}

return self;
}

问题是,此时,self.frame.size.width 始终返回 320.0,因此 UILabels 的大小不正确。我该如何克服这个问题?

最佳答案

将第二个标签的autoresizingMask设置为UIViewAutoresizingFlexibleWidth

如果您的需求比 autoresizingMask 所能表示的更复杂,您需要实现自己的 layoutSubviews

关于ios - initWithStyle 上的 UITableViewCell 宽度 :reuseIdentifier:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8955301/

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