其他人都注意到iOS 7以与内置accessoryTypes不同的方式布置自定义accessoryViews?
像这样:
最上面的一个是使用:
完成的cell.accessoryView = cell.accessoryButton;
(其中accessoryButton是一个自定义的UIButton),而第二个是使用:
完成的cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
相同的代码,相同的应用程序,相同的Xcode,但在iOS 6上运行:
这是SDK中的错误吗?或者我可以通过代码控制的东西?
答案 0 :(得分:23)
如果您对UITableViewCell
进行细分,则可以在layoutSubviews
- (void)layoutSubviews {
[super layoutSubviews];
CGRect accessoryViewFrame = self.accessoryView.frame;
accessoryViewFrame.origin.x = CGRectGetWidth(self.bounds) - CGRectGetWidth(accessoryViewFrame);
self.accessoryView.frame = accessoryViewFrame;
}
答案 1 :(得分:0)
添加子视图而不是accessoryView
UIButton *indicatorBtn = [UIButton buttonWithType:UIButtonTypeCustom];
indicatorBtn.frame = CGRectMake(cell.contentView.frame.size.width-55, 2, 50, 50);
[indicatorBtn setBackgroundImage:[UIImage imageNamed:@"right_indicator.png"]
forState:UIControlStateNormal];
indicatorBtn.backgroundColor = [UIColor clearColor];
//indicatorBtn.alpha = 0.5;
indicatorBtn.tag = indexPath.row;
[indicatorBtnaddTarget:self action:@selector(method:)
forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:indicatorBtn];