如何覆盖UITableViewCell中的accessoryView来改变它的位置

Fle*_*lea 8 iphone uitableview ios

默认情况下,accessoryViewUITableViewCell位于最右边的单元格.我正在UITableViewCell对它进行分类,试图改变这个位置,将它移到左边,但是,它没有效果,它仍然在右边.关于如何做到这一点的任何想法?

- (void) layoutSubviews
{
    [super layoutSubviews];
    self.accessoryView.frame = CGRectMake(100, self.accessoryView.frame.origin.y, self.accessoryView.frame.size.width, self.accessoryView.frame.size.height);
    self.accessoryView.layer.borderWidth = 1;
    self.accessoryView.layer.borderColor = [[UIColor redColor] CGColor];
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Wai*_*ain 6

layoutSubviews在您的单元子类中实现,首先调用super,然后修改要更改的子视图的帧.


Fle*_*lea 0

根据马特的提示,我发现执行此操作的唯一方法是仅使用我自己的UIImageView图像并使用我选择的图像,然后将坐标设置frame为我需要的坐标。这使得该公司accessoryView能够扩大规模。显然这是操纵它的唯一方法。

UIImage *indicatorImage = [UIImage imageNamed:@"BV-icon_57x57"];
        UIImageView *view = [[UIImageView alloc] initWithImage:indicatorImage];
        view.frame = CGRectMake(0, 0, 100, 20);
        [view setContentMode:UIViewContentModeLeft];//without this line the image will just be stretched;
        cell.accessoryView = view;
Run Code Online (Sandbox Code Playgroud)

  • @FahimParkar,这绝对是晚了一天,而且少了一美元,但今晚我一直在解决这个问题,并找出如何让 Flea 的解决方案发挥作用。您必须使用“setContentMode”来左对齐图像。否则它只会拉伸它。我已经编辑了解决方案。 (2认同)