2011-03-09 79 views
2

我创建了一个表格,它在分配的图像旁边显示一些用户输入(类似于Facebook应用程序中的墙贴)。但是,默认对齐方式是沿着单元格的高度居中。我希望默认对齐位于左上角。有没有办法做到这一点,而不创建自定义单元格?这是我的代码:对齐UITableView中的图像

- (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; 

}

的感谢!

回答

1

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

在Xcode文档中,请参阅Table View编程指南>仔细查看表格视图单元格>自定义单元格&列表5-3将子视图添加到单元格的内容视图。