2011-03-09 75 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將子視圖添加到單元格的內容視圖。