我正在向UICollectionViewCell添加子视图。我正在编程添加约束来填充单元格,但宽度不填充单元格。子视图宽度不适合superview与自动布局
当我在视图调试器中查看它时,它表示位置不明确。这是怎么回事,因为我指定所有4面都固定在超视图上?
这就是调试器中的视图。内,白色视图应该适合父母宽度(蓝色边框):
检查在父视图的约束示出该与“位置模糊”警告:
我正在使用的代码如下:
[self.contentView addSubview:calloutView];
calloutView.translatesAutoresizingMaskIntoConstraints = NO;
self.contentView.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[calloutView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(calloutView) ]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[calloutView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(calloutView) ]];
凡你使用这个代码? –
UICollectionViewDelegate创建一个单元格,然后调用包含此代码的单元格设置方法 – zorro2b
,但此代码位于您的单元格内或您的viewController中? –