您的位置:首页 > 移动开发 > IOS开发

iOS 如何更改Cell中默认accessoryView的位置

2016-05-25 11:30 1251 查看
如果你不想自定义Cell,又希望改变
accessoryView
的位置的话,很简单,在子Cell类中的
layoutSubviews
方法中去修改
accessoryView
frame
。(别忘了调用
[super layoutSubviews]
)

- (void)layoutSubviews
{
[super layoutSubviews];

CGRect adjustedFrame = self.accessoryView.frame;
adjustedFrame.origin.x += 10.0f;
self.accessoryView.frame = adjustedFrame;
}


直接在别的位置修改是没有效果的!~

如果不希望子类化Cell,还有个“作假”的办法,就是把accessoryView里面塞进去的view宽度变大,然后调整对内对齐方式。

static CGFloat const kRightOffset = 10.0;

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


该方法是我试验是能够得到效果是往左移,往右移的办不到(估计默认给
cell.accessoryView
加了右边的
margin




References : Can a standard accessory view be in a different position within a uitableviewcell? – Stack Overflow

How to override accessoryView in UITableViewCell to change it’s position – Stack Overflow
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  accessoryV ios Cell