开发者

set position of uitableviewcellaccessory

By default the UITalbeViewCellAccessory's position is in the middle of the cell off to the right. I want to shift it 29 pixels on the Y axis (move it down 29 pixels). How can i do this? I tried setting the accessoryView's frame but th开发者_JAVA百科at didn't work.

Thanks,


Set the accessoryView initial frame is affectless, it is changed any time that the cell does a layout, you need to:

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

This is a simple way to set a custom position for the accessoryView that is persisted in any cell status


A trick for UIImageView's as accessoryView (slightly modified, may contain typos):

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; });


You cannot move the default UITableViewCellAccessoryType. You need to just add a custom view to the cell:

[cell.contentView addSubview:aView];


The default UITableViewCell accessoryView property is hard-coded proportional using values from the UITableViewCell and UITableView frame property

(something like UITableViewCell.accessoryView.frame.x = UITableView.frame.width - *30, and UITableViewCell.accessoryView.frame.y = UITableViewCell.frame.height / 2 - *10) (*rough estimate values by me)

For example, if you would lower the UITableView.frame.width value, the accessoryView "absolute" x-position moves to the left, and, similarly, you can adjust the "absolute" y-position by manipulating the UITableViewCell height value, and, possibly, you could cascade 2 UITableViewCell's and set the inner one frame height larger than its parent's so that the position of the accessory view (which is positioned to about half the height of the inner UITableViewCell) gets a lower "absolute" y-position value.

Not a pretty solution, but that's the one way without custom accessory views.


For that you have to go for custom accessory view...because its easier way to change the location of UITableViewCellAccessory and for custom accessory view have a look at Custom Accessory View For UITableView in iPhone

Now set the accessories wherever you want.

Good Luck!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜