gpt4 book ai didi

ios - 向 TableView 中的行添加边距/填充 - objective-c

转载 作者:行者123 更新时间:2023-11-29 01:00:11 25 4
gpt4 key购买 nike

我是 iOS 开发的新手,我浪费了很多时间来尝试一些我认为应该很容易的事情。我试图增加我的行的高度,这奏效了,但问题是图像的尺寸也增加了。所以我正在寻找一种解决方案,比如在我的行中添加边距/填充,图像大小仍然相同,而不是像左边的照片那样?正确的照片是我要解释的一个很好的例子。

enter image description here

有人为此提供了一个很好的代码示例吗?谢谢你! :)

TableView 代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
Personen *myPersoon = self.personen[indexPath.row];

// Configure the cell...
cell.imageView.image = [UIImage imageNamed:myPersoon.foto];
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@",
myPersoon.naam, myPersoon.voornaam];

return cell;
}

最佳答案

创建您自己的单元格,而不是使用 UITableViewCell 的默认标题和 ImageView 。制作 Storyboard,将单元格添加到 tableView,并添加 ImageView /标签/按钮或其他内容,添加约束,然后您可以拥有任何您想要的布局/定位。

您的 TableView 非常简单,您不想创建自己的吗?或者,您仍然可以将它子类化并使用 layoutSubviews: 来改变位置:

- (void)layoutSubviews {

[super layoutSubviews];

CGRect frame = self.imageView.frame;
frame.origin.y = (self.frame.size.height - kImageViewDiameter ) / 2.0f;
frame.size.height = kImageViewDiameter;
frame.size.width = kImageViewDiameter;
self.imageView.frame = frame;
}

关于ios - 向 TableView 中的行添加边距/填充 - objective-c ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37104155/

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