您好,我是iOS的初学者,我正在尝试使用自动布局accessoryButton
在tableViewCell
上添加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
,我在这做错了什么?
答案 0 :(得分:0)
您无需为accessoryView
设置自动布局。
您可以设置accessoryView
,如下面的语法。
cell.accessoryView = accessorybutton;