如何使用自动布局以编程方式在tableview单元格上修复accessoryButton

时间:2015-07-24 14:15:24

标签: ios swift

您好,我是iOS的初学者,我正在尝试使用自动布局accessoryButtontableViewCell上添加constraintsWithVisualFormat,但它没有添加,请帮助我一些

    accessorybutton = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellbutton.png"]];
    accessorybutton.translatesAutoresizingMaskIntoConstraints = NO;
    [accessorybutton setContentMode:UIViewContentModeScaleAspectFit];
    [accessorybutton sizeToFit];
    [Cell.contentView addSubview:accessorybutton];

    NSDictionary * views = NSDictionaryOfVariableBindings(accessoryView);

    NSArray * horizentalConstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[accessorybutton]-20-|" options:0 metrics:nil views:views];

    NSArray * verticalConstraint = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-5-[accessorybutton]-5-|"options:0 metrics:nil views:views];

但是accessoryView没有添加UITableViewCell,我在这做错了什么?

1 个答案:

答案 0 :(得分:0)

您无需为accessoryView设置自动布局。

您可以设置accessoryView,如下面的语法。

cell.accessoryView = accessorybutton;