【发布时间】:2015-01-01 01:57:28
【问题描述】:
我有一个Image View,我希望根据屏幕大小更改高度和宽度:
- iPhone 6 Plus 414x414
- iPhone 6 375x375
- iPhone 5s 320x320
我在情节提要中对 Image View 施加的任何约束似乎都将其硬编码(即约束高度和宽度),因此它适用于一种尺寸,但不适用于所有其他尺寸。
我们将不胜感激,谢谢!
更新
我有一个自定义表格视图单元TableViewCellTwo,它位于表格视图控制器TableViewController 的内部。
TableViewController.m
TableViewCellTwo *api2Cell = [tableView dequeueReusableCellWithIdentifier:@"YourAPI2Cell"];
api2Cell.labelHeadline.text = user;
api2Cell.labelDescription.text = cap;
api2Cell.labelPublished.text = date;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 600.0;
// SDWebImage
if ([data.images count] == 0) {
NSLog(@"Images Count: %lu", (unsigned long)data.images.count);
}
else {
Images *imageLocal = [data.images objectAtIndex:0];
StandardResolution *standardResolutionLocal = [imageLocal.standard_resolution objectAtIndex:0];
NSString *imageURL = [NSString stringWithFormat:@"%@", standardResolutionLocal.url];
__weak TableViewCellTwo *wcell = api2Cell;
[wcell.imageView
sd_setImageWithURL:[NSURL URLWithString:imageURL]
placeholderImage:[UIImage imageNamed:@"320x180.gif"]
];
}
return api2Cell;
}
【问题讨论】:
-
不要使用高度或宽度约束,使用“固定到超级视图”。
-
感谢您的回复!那么用pin来超级查看左右零点呢?
-
是的,你总是需要约束来定义它的大小,另一个来定义它的位置,在这种情况下,如果你固定左、右、顶部和底部,它应该可以工作,或者如果你想要 SPECIFIC尺寸,对于这些屏幕,您可以通过编程检测当前屏幕尺寸来修改它们
-
我想我不确定我会使用什么作为顶部和底部引脚的值。我上面的标签之间已经有了垂直间距,然后从图像视图底部到容器边距的底部间距?
-
基本上当我从图像视图中清除所有约束时:如果我将 0 作为顶部、底部、左侧、右侧的引脚...它仍然在做同样的事情(在与 iPhone 6 Plus 相比,更适合 iPhone 6)
标签: ios iphone uiimageview storyboard autolayout