El texto de UILabel no se redimensiona automáticamente usando Auto Layout
Estoy tratando de implementar una restricciónUITableViewCell
subclase y todo funciona perfectamente, excepto por elUILabel
. Las restricciones que he configurado definitivamente se aplican, pero el texto dentro de la etiqueta no cambia de tamaño a un tamaño de fuente más pequeño cuando las restricciones chocan. En cambio, la altura de la UILabel se trunca y la fuente sigue siendo del mismo tamaño, lo que significa que las letras se cortan en la parte superior e inferior.
¿Hay algún método al que tenga que llamar para que funcione? Pensaría que el diseño automático sería lo suficientemente inteligente como para redimensionar automáticamente el tamaño de la fuente, así que estoy un poco perdido en cuanto a por qué sucede esto.
Código Relevante:
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];
Básicamente, estas restricciones están destinadas a imponer una celda dondeotherView
está a la izquierda,aTextField
está a la derecha deotherView
en el mismo nivel y, y la etiqueta está debajoaTextField
ya la derecha del fondo deotherView
.
Como de costumbre, gracias por cualquier ayuda con esto.