如何根据屏幕尺寸设置背景图像?

时间:2014-08-30 09:04:58

标签: ios cocoa-touch screen-size

我想根据屏幕尺寸设置图像。我已经查了很多代码,但我还没有找到合适的解决方案。我正在使用Xcode 5.1.1和Iphone Retina 4inch。每当我添加背景图像时,它就会变得很大并且超出了屏幕尺寸。请帮助我。

2 个答案:

答案 0 :(得分:0)

使用Anbu答案中的代码获取屏幕高度并将图像设置为aspectFit,以避免它变得庞大且超出范围:

yourImageview.contentMode = UIViewContentModeScaleAspectFit;
yourImageview.clipsToBounds = YES;

答案 1 :(得分:0)

如果您的观点直接添加到UIViewController,则应使用viewWillLayoutSubviewsdoc)方法进行调整大小。像这样:

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    self.imageView.frame = self.bounds;
}
相关问题