繁体   English   中英

UIImageView:全屏图像

[英]UIImageView: full screen image

我想在iPhone上看到全屏图像。 我必须设置多少个像素? iPhone 3和4的宽度和高度是否不同?

我的源代码:

NSString *filePath = [[NSBundle mainBundle] pathForResource:theProduct.image ofType:@"png"]; 
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:filePath]];
img.frame = CGRectMake(0.0, 0.0, ?, ?);
[self.view addSubview:img];

除了问号,我应该放些什么?

非常感谢,斯特凡诺

尝试将UIImageView的框架设置为[[UIScreen mainScreen] applicationFrame]

这会将UIImageView设置为使用该应用程序可用的所有空间,如果状态栏不可见则不包括该状态栏。

您应该将其设置为旧版iPhone的尺寸:320 x 480像素。 然后,iPhone 4会将其翻倍以适合屏幕。 如果您不希望看到像素化,则需要使用另一个@ 2x图像,尺寸为640 x 960。

该问题已得到解答(状态栏被移除后,请使用320 x 480或320 x 460)。

但是,作为解决类似问题的一种方法:在Xcode中,将UIImageView放置在xib中; 适当调整其大小,然后在右窗格中显示“大小检查器”(从右侧进入第二个选项卡)。 它给出了矩形框的宽度和高度。 如果您不希望缩放图像(或者如果您想要1:1缩放),请使用此宽度和高度作为图像的大小。 同样(如上)使用双分辨率图像@ 2x进行视网膜显示。

这是一个很老的线程,所以只需更新约束条件。

imageView?.translatesAutoresizingMaskIntoConstraints = false
imageView?.contentMode = .scaleAspectFit
view.backgroundColor=UIColor.blue
view.addSubview(self.imageView!)

    let height = NSLayoutConstraint(item: imageView!, attribute: .height, relatedBy: .equal, toItem: view, attribute: .height, multiplier: 1, constant: 0)
    let width = NSLayoutConstraint(item: imageView!, attribute: .width, relatedBy: .equal, toItem: view, attribute: .width, multiplier: 1, constant: 0)
    view.addConstraints([height, width])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM