【问题标题】:How to draw image on the right side of the UITableView cell on iOS 7 on iPad?如何在 iPad 上的 iOS 7 上的 UITableView 单元格右侧绘制图像?
【发布时间】:2013-09-13 21:53:37
【问题描述】:

如何在 iPad 上 iOS 7 的 UITableView 单元格右侧绘制图像?

尝试了以下代码但无济于事:

  1. tableView.contentInset = UIEdgeInsetsZero;
  2. [cell contentView].frame = CGRectMake(0, [cell contentView].frame.origin.y, cell.frame.size.width, [cell contentView].frame.size.height);

【问题讨论】:

  • 您是否尝试过使用accessoryView 属性?

标签: ipad uitableview ios7


【解决方案1】:

您很可能希望在UITableViewCell 上设置accessoryView 属性。这将在单元格的右侧放置一个图像视图:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        // Configure cell
    }

    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"<some image name>.png"]];
    cell.accessoryView = image;
}

【讨论】:

  • 那我根本看不到图像。如何显示附件视图?还是去掉它,将 contentView 扩展到表格的右边框?
  • cell.accessoryView = image 有帮助,谢谢!但图像不在垂直轴上。
  • 我认为垂直对齐会影响图像的大小和形状。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多