我使用autolayout UIScrollView来显示对象的一些属性.我从网络服务下载这个信息.scrollview具有恒定的宽度(因为我不希望有垂直滚动行为),并且其子视图使用一组约束来尊重此宽度,但我不能UILabel动态地增加其高度.
我编码所有内容,我使用viewDidLoad选择器来创建子视图...
- (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;
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
您可以观察self.detailContentScrollView变量,这是IBOulet从视图控制器的笔尖创建的.
然后我使用updateConstraints选择器...... …