制約付きサブクラスを実装しようとしていますが、.UITableViewCellを除いてすべてが完全に機能していUILabelます。私が設定した制約は確実に適用されていますが、制約が衝突しても、ラベル内のテキストのサイズが小さいフォント サイズに変更されません。代わりに、UILabel の高さが切り捨てられ、フォントは同じサイズのままです。つまり、文字が上下で切り取られます。
これを機能させるために呼び出さなければならないメソッドはありますか? 自動レイアウトはフォントサイズを自動的にサイズ変更するのに十分スマートだと思うので、なぜこれが起こっているのかわかりません。
関連コード:
self.label = [[UILabel alloc] initWithFrame:CGRectZero];
self.label.textColor = [UIColor whiteColor];
self.label.translatesAutoresizingMaskIntoConstraints = NO;
self.label.textAlignment = NSTextAlignmentCenter;
self.label.numberOfLines = 1;
[self.contentView addSubview:self.label];
NSLayoutConstraint *otherViewToLabelHorizontalConstraint = // Make sure that the label is always to the right of the other view.
[NSLayoutConstraint constraintWithItem:self.label
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:self.otherView
attribute:NSLayoutAttributeRight
multiplier:1.0
constant:0.0];
NSLayoutConstraint *aTextFieldToLabelVerticalConstraint =
[NSLayoutConstraint constraintWithItem:self.label
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationGreaterThanOrEqual
toItem:self.aTextField
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0.0];
基本的に、これらの制約は、同じ y レベルでotherViewが左側にaTextFieldあり、 が右側にあり、ラベルがの下部と右側にあるセルを強制することを目的としています。otherViewaTextFieldotherView
いつものように、これについて助けてくれてありがとう。