Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 用于将UILabel固定到UICollectionViewCell contentView按钮的自动布局约束_Ios_Objective C_Uiview_Autolayout - Fatal编程技术网

Ios 用于将UILabel固定到UICollectionViewCell contentView按钮的自动布局约束

Ios 用于将UILabel固定到UICollectionViewCell contentView按钮的自动布局约束,ios,objective-c,uiview,autolayout,Ios,Objective C,Uiview,Autolayout,我试图使用可视化格式语言向UICollectionViewCell子类添加一个简单的约束。我只希望将UILabel固定到contentView的底部。这是我的初始化代码: - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if(self) { _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 128, 50)

我试图使用可视化格式语言向UICollectionViewCell子类添加一个简单的约束。我只希望将UILabel固定到contentView的底部。这是我的初始化代码:

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 128, 50)];
        _label.font = [[UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline1] fontWithSize:20.0];
        _label.lineBreakMode = NSLineBreakByWordWrapping;
        _label.numberOfLines = 2;
       _label.contentMode = UIViewContentModeBottom;
       _label.backgroundColor = [UIColor blackColor];
       [self.contentView addSubview:_label];
        [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_label]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_label)]];
    }
    return self;
}
下面是我运行应用程序时收到的示例日志消息

Unable to simultaneously satisfy constraints.
Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0xa3aa620 V:[UILabel:0xa3aa270]-(0)-|   (Names: '|':UIView:0xa3aa010 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x8b9b2d0 h=--& v=--& UILabel:0xa3aa270.midY == + 25>",
    "<NSAutoresizingMaskLayoutConstraint:0x8b9bba0 h=--& v=--& V:[UILabel:0xa3aa270(50)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x8bd1290 h=-&- v=-&- UIView:0xa3aa010.height == STStationGroupCollectionViewCell:0xa3a9f40.height>",
    "<NSAutoresizingMaskLayoutConstraint:0x8bb7ee0 h=--& v=--& V:[STStationGroupCollectionViewCell:0xa3a9f40(128)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0xa3aa620 V:[UILabel:0xa3aa270]-(0)-|   (Names: '|':UIView:0xa3aa010 )>
无法同时满足约束。
无法同时满足约束。
可能下面列表中至少有一个约束是您不想要的。试着这样做:(1)看看每个约束,试着找出你不期望的约束;(2) 找到添加了不需要的约束的代码,然后修复它。(注意:如果您看到不理解的NSAutoresizingMaskLayoutConstraints,请参阅UIView属性TranslatesAutoResizingMaskToConstraints的文档)
(
"",
"",
"",
"",
""
)
将尝试通过打破约束进行恢复
非常感谢您的帮助。谢谢

尝试添加:

_label.translatesAutoresizingMaskIntoConstraints = NO;
似乎有一个autoresize约束试图修复标签的midY