gpt4 book ai didi

cocoa-touch - 在 UITableView 中对齐图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:57:23 26 4
gpt4 key购买 nike

我创建了一个表格,显示一些用户输入以及指定的图像(有点像 facebook 应用程序上的墙贴)。但是,默认对齐方式是沿着单元格的高度居中。我希望默认对齐方式位于左上角。有没有办法在不创建自定义单元格的情况下做到这一点?这是我的代码:

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

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0];
}

// Configure the cell.
[[cell imageView] setImage:[UIImage imageNamed:[[[userData objectAtIndex:indexPath.section] objectAtIndex: indexPath.row] objectForKey:@"picture"]]];
[[cell textLabel] setText:[[[userData objectAtIndex:indexPath.section] objectAtIndex: indexPath.row] objectForKey:@"post"]];

return cell;

谢谢!

最佳答案

如果您需要更好地控制其布局,请不要使用提供的图像属性,而是将您自己的 UIImageView 作为 subview 添加到单元格,并根据需要定位它。

在 Xcode 文档中,请参阅 TableView 编程指南 > 深入了解 TableView 单元格 > 自定义单元格和 list 5-3 添加 subview 到单元格的内容 View 。

关于cocoa-touch - 在 UITableView 中对齐图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5240118/

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