开发者

Aligning an image in a UITableView

开发者 https://www.devze.com 2023-02-15 11:02 出处:网络
i\'ve created a table that displays some user input alongside an assigned image (kind of like a wall post on a facebook app). However, the default alignment is centered along the height of the cell. I

i've created a table that displays some user input alongside an assigned image (kind of like a wall post on a facebook app). However, the default alignment is centered along the height of the cell. I would like the default alignment to be in the upper left corner. Is there a way to do this without creating custom cells? this is my code:

- (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.lineBrea开发者_高级运维kMode = 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;

}

thanks!


Don't use the supplied image property if you need better control over its layout, but instead add your own UIImageView as a subview to the cell and position it however you need.

In the Xcode docs, see the Table View Programming Guide > A Closer Look at Table-View Cells > Customizing Cells & listing 5-3 Adding subviews to a cell’s content view.

0

精彩评论

暂无评论...
验证码 换一张
取 消