uitableviewcellaccessory的设置位置

问题描述:

默认情况下,UITalbeViewCellAccessory的位置位于单元格中间向右。我想在Y轴上移动它29个像素(向下移动29个像素)。我怎样才能做到这一点?我试图设置accessoryView的框架,但没有奏效。uitableviewcellaccessory的设置位置

感谢,

设置accessoryView的初步框架是affectless,它改变了细胞做了布局任何时候,你需要:

- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 
    self.accessoryView.center = CGPointMake($yourX, $yourY); 
} 

这是一个简单的方法来设置一个自定义位置accessoryView坚持任何单元状态

对于您必须去custom accessory view ......因为它更简单的方法来改变UITableViewCellAccessory和定制附件视图位置看看Custom Accessory View For UITableView in iPhone

现在设置任何你想要的配件。

祝你好运!

+0

我很害怕你会这么说。任何机会,你知道一个简单的方法来抓住他们的默认图像,所以我不必让我自己> – odyth 2011-03-29 04:36:57

+0

:)不,你不能那样做.....你必须把你自己的图像 – Sudhanshu 2011-03-29 04:48:59

您不能移动默认UITableViewCellAccessoryType。你只是需要添加自定义视图到小区:

[cell.contentView addSubview:aView]; 

一种的UIImageView的为accessoryView的伎俩(略作修改,可能包含错别字):

cell.accessoryView = ({UIImageView * imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image.png"]]; 
        CGRect frame = imgV.frame; 
        frame.size.width = frame.size.width + 10; //Push left by 10 
        imgV.frame = frame; 
        [imgV setContentMode:UIViewContentModeLeft]; 
        imgV; }); 

默认UITableViewCellaccessoryView属性是硬编码从UITableViewCellUITableView框架财产比例使用值

(像UITableViewCell.accessoryView.frame.x = UITableView.frame.width - *30, and UITableViewCell.accessoryView.frame.y = UITableViewCell.frame.height/2 - *10)(*由我粗略估计值)

例如,如果您要降低UITableView.frame.width值,则accessoryView“绝对”x位置向左移动,同样,您可以通过操纵高度值调整“绝对”y位置,可能的话,您可以级联2 UITableViewCell的并将内部的一个框架高度设置为大于其父母的高度,以便配件视图的位置(位于内部高度的约一半的高度)获得较低的“绝对”位置值。

不是一个漂亮的解决方案,但这是没有自定义附件视图的一种方式。