I am using autolayout with UIScrollView
to show some attributes from an object. I download this information dinamically from web service. The scrollview has a constant width (because I don't want to have a vertical scroll behavior) and its subviews respect this width with a group of constraints, but I can't to increase the UILabel
's height dynamically.
I code everything and I use viewDidLoad
selector to create subviews...
- (void)viewDidLoad {
[super viewDidLoad];
.
.
.
UILabel *descriptionLabel = [[UILabel alloc] initWithFrame:CGRectZero];
descriptionLabel.translatesAutoresizingMaskIntoConstraints = NO;
descriptionLabel.numberOfLines = 0;
descriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
descriptionLabel.opaque = YES;
descriptionLabel.backgroundColor = [UIColor clearColor];
descriptionLabel.textColor = [UIColor whiteColor];
descriptionLabel.textAlignment = NSTextAlignmentRight;
descriptionLabel.font = [UIFont appetitoMediumItalicFontWithSize:15.0f];
descriptionLabel.text = NSLocalizedStringFromTable(@"APT_DISH_DETAIL_DESCRIPTION", @"DishDetail", @"Etiqueta que contiene la descripción del platillo");
[descriptionLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[self.detailContentScrollView addSubview:descriptionLabel];
self.descriptionLabelS = descriptionLabel;
.
.
.
}
You can watch the self.detailContentScrollView
variable, this is an IBOulet
created from view controller's nib.
Then I use the updateConstraints
selector...
- (void)updateConstraints {
[super updateConstraints];
// This dictionary has more variables, ok
NSDictionary *viewsDict = @{@"dish_description_label": self.descriptionLabelS};
.
.
.
[self.descriptionLabelS setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
[self.detailContentScrollView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[view1][dish_description_label]-[view2][view3][view4]-|" options:0 metrics:nil views:viewsDict]];
.
.
.
}
and finally, when I receive the web service's info, I send sizeToFit
's UILabel
selector and layoutIfNeeded
from the scrollview. But my UILabel
never resizes itself with the new content. What am I doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…