我是 iOS 开发的新手,我浪费了很多时间来尝试一些我认为应该很容易的事情。我试图增加我的行的高度,这奏效了,但问题是图像的尺寸也增加了。 所以我正在寻找一种解决方案,比如在我的行中添加边距/填充,图像大小仍然相同,而不是像左边的照片那样?正确的照片是我要解释的一个很好的例子。
有人为此提供了一个很好的代码示例吗?谢谢你! :)
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/