【问题标题】:Aligning an image in a UITableView在 UITableView 中对齐图像
【发布时间】:2011-03-09 00:40:29
【问题描述】:

我创建了一个表格,在分配的图像旁边显示一些用户输入(有点像 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;

}

谢谢!

【问题讨论】:

    标签: cocoa-touch ios uitableview uiimageview


    【解决方案1】:

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

    在 Xcode 文档中,请参阅 Table View Programming Guide > A Closer Look at Table-View Cells > Customizing Cells & Listing 5-3 添加子视图到单元格的内容视图。

    【讨论】:

      猜你喜欢
      • 2011-07-16
      • 1970-01-01
      • 2016-10-07
      • 2013-03-08
      • 2012-07-10
      • 2016-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多