2013-06-26 2 views
1

시각적 형식 지정 언어를 사용하여 UICollectionViewCell 하위 클래스에 간단한 제약 조건을 추가하려고합니다. 나는 UILabel을 contentView의 맨 아래에 고정시키고 싶다. 내 초기화 코드는 다음과 같습니다.UICollectionViewCell의 button에 UILabel을 고정하기위한 Autolayout 제약 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)> 

모든 도움을 주시면 감사하겠습니다. 감사! 추가

답변

2

봅니다 :

_label.translatesAutoresizingMaskIntoConstraints = NO; 

라벨의 midY를 해결하기 위해 노력 자동 크기 제약이있는 것 같습니다.

관련 문제