2011-01-16 12 views
0

iPhone에서 전체 화면 이미지를보고 싶습니다. 얼마나 많은 픽셀을 설정해야합니까? 너비와 높이가 아이폰 3과 4와 다른가요?UIImageView : 전체 화면 이미지

내 소스 코드 :

나는 물음표 대신 넣어해야합니까
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]; 

?

많은 감사, 스테파노

답변

1

이전 iPhones : 320 x 480 픽셀의 크기로 설정해야합니다. iPhone 4는 화면에 맞게이 값을 두 배로 늘립니다. 픽셀 화를보고 싶지 않으면 640x960 크기의 또 다른 @ 2x 이미지가 필요합니다.

8

[[UIScreen mainScreen] applicationFrame]에있는 UIImageView의 프레임을 설정하십시오.

이렇게하면 표시되는 경우 상태 표시 줄을 제외한 앱에서 사용할 수있는 모든 공간을 사용하도록 UIImageView를 설정합니다.

+0

이것은 좋은 생각 인 것 같았지만 시도한 때 방향이 잘못되었습니다. http://stackoverflow.com/questions/2664980/uiscreen-applicationframe-returning-incorrect-rectangle-on-landscape-application은 미래의 독자들에게 흥미로울 수 있습니다. – PeterT

0

질문에 이미 답변되었습니다 (상태 표시 줄을 제거한 후 320x480 또는 320x460 사용).

비슷한 문제를 해결하는 방법 : Xcode에서 xib에 UIImageView를 놓기; 오른쪽 구획에서 적절하게 크기를 지정하십시오. "크기 속성"(오른쪽에서 두 번째 탭)을 표시하십시오. 프레임 사각형의 폭과 높이를 제공합니다. 확대/축소하지 않으려는 경우 (또는 1 : 1 비율을 원할 경우) 이미지의 크기로이 너비와 높이를 사용하십시오. 또한 (위와 같이) 망막 디스플레이의 경우 2 배속 이미지를 2 배 사용합니다.

0

이것은 매우 오래된 스레드이므로 Constraints를 사용하여이 작업을 수행하는 방법을 업데이트하는 것입니다.

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])