2012-11-21 3 views
3

내 iPhone 앱에서 프로그래밍 방식으로 크기를 조정하고 UIImageView를 이동하여 iPhone 화면의 왼쪽 위 모서리로 표시하고 폭이 넓고 화면의 높이만큼 키가 크다. 그래서 나는 다음과 같은 코드를 사용하고 수행합니다프레임 변경 프레임의 크기가 조정되지 않습니다. UIImageView

-(void)viewDidLoad 
{ 
    //Getting screen size 
    CGRect screenSize = [[UIScreen mainScreen]bounds]; 

    //Creating the new frame for the UIImageView 
    CGRect arect = CGRectMake(0, 0, screenSize.size.height, screenSize.size.height); 
    //Setting the image to show 

    UIImage *image = [UIImage imageNamed:@"Adele.jpg"]; 
    self.imageView.image = image; 

    //Setting new frame and contentmode 
    self.imageView.frame = arect; 
    self.imageView.contentMode = UIViewContentModeScaleToFill; 
} 

self.imageView 내가 인터페이스 빌더로 만든 콘센트입니다.

문제는 응용 프로그램을 시작할 때이 코드가 UIImageView의 프레임에 영향을 미치지 않는 것입니다. 이미지 뷰의 실제 위치는 IB로 만들 때 설정 한 크기와 동일한 위치에 표시됩니다.

이 코드가 작동하지 않는 이유에 대해 의견이있는 사람이 있습니까? 내가 뭘 놓치고 있니?

답변

5

다른 콘텐츠 모드가 필요할 수도 있습니다.

UIViewContentModeScaleAspectFit 시도해보십시오. 맥락에서 :

self.imageView.frame = arect; 
self.imageView.contentMode = UIViewContentModeScaleToFill; 

그건 당신이 initWithFrame을 할 수있는 작동하지 않는 경우 :

CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f); 
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect]; 
[myImage setImage:[UIImage imageNamed:@"myImage.png"]]; 

source

+2

initWithFrame'했던'비록'UIViewContentModeScaleAspectFit' 작동하지 않았다! 어쨌든 이상한 행동이 아니십니까? 이미 존재하는'UIImageView' 인스턴스의 프레임을 변경하면 안된다는 말입니까? – BigLex

+4

제게있어, 트릭을 한 것은 AspectFill이었습니다. – cph2117

관련 문제