UITableViewCell设置图片靠右显示?

有没有方法设置UITableViewCell.图片显示在单元格的右边而不是左边?或者我是否需要在布局的右边添加单独的UIImageView?

原问题:UITableViewCell with image on the right?

阅读 11.4k
1 个回答

Alex Wayne
不需要,但是你可以简单给表格单元格添加作为辅助视图的图像视图来获得同样的效果。

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"foo.png"]];
cell.accessoryView = imageView;
[imageView release];

user283846
这是给每个cell添加不同图片的方法,尝试一下。

// 自定义表视图单元格的外观
- (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];
}

if(indexPath.row == 0)
{
    cell.image = [UIImage imageNamed:@"image.png"];
}

else if (indexPath.row == 1)
{
    cell.image = [UIImage imageNamed:@"image1.png"];
}

Camsoft
子类的UITableViewCell并且覆盖layoutSubviews ,然后调整self.textLabel, self.detailTextLabel 和 self.imageView views的框架。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进