动态UI元素的大小类问题

时间:2015-07-28 05:27:01

标签: ios size-classes

我在故事板上使用了UI元素的大小类,但是我动态创建的ui元素是什么。

假设我有一个带有框架10,10,200,25的 UILabel ...我在不同的设备上显示不同,如何通过大小类来主,我假设我们手动必须设置缺少的约束但如果有人能指出我正确的解释。

[containerView addConstraints:[NSLayoutConstraint 
constraintsWithVisualFormat:@"V:|[scrollView]|"                                                                             
options:kNilOptions
metrics:nil
views:viewsDictionary]];

1 个答案:

答案 0 :(得分:0)

如果要设置编程约束,则需要将以下约束添加到添加了UILabel的UILabel和UIView中。

lblName.translatesAutoresizingMaskIntoConstraints = NO;    NSDictionary * usageViewsDictionary = @ {@“lblControl”:lblName}; [lblName addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@“V:[lblControl(25)]”                                                                             选项:0                                                                               指标:无                                                                               的观点:usageViewsDictionary]];         [lblName addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@“H:[lblControl(200)]”                                                                             选项:0                                                                               指标:无                                                                               的观点:usageViewsDictionary]];   [containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@“V:| -10- [lblControl]”                                                                             选项:0                                                                             指标:无                                                                               的观点:usageViewsDictionary]];         [containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@“H:| -10- [lblControl]”                                                                              选项:0                                                                              指标:无                                                                                的观点:usageViewsDictionary]];