[英]Aligning an image in a UITableView
我創建了一個表,在分配的圖像旁邊顯示一些用戶輸入(有點像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;
}
謝謝!
如果您需要更好地控制其布局,請不要使用提供的image屬性,而應將自己的UIImageView作為子視圖添加到單元格中,並根據需要對其進行定位。
在Xcode文檔中,請參閱《表視圖編程指南》>“對表視圖單元格的更深入了解”>“自定義單元格”並列出5-3將子視圖添加到單元格的內容視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.