2012-01-11 2 views
-1

jpg를 UIImageView에로드했습니다. 이미지는 iPhone 화면에 비해 큽니다. 특정 CGRect 프레임의 크기를 조정하려면 어떻게해야합니까?UIImageView에서 JPG의 크기를 조정하는 방법은 무엇입니까?

UIImageView *uivSplash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iPhone-Splash.jpg"]]; 
[self.view addSubview:uivSplash]; 
+1

오른쪽의 관련 상자를 확인하십시오.이 질문의 답은 100 번입니다. – vikingosegundo

답변

1

UIImageView 그냥 UIView, 그래서 당신은 frame 속성을 변경할 수 있습니다.

uivSplash.frame = CGRectMake(0, 0, width, height); 
1

당신이 좋아하는 방법을 원할 것이다 다음

CGFloat newWidth = whateverYourDesiredWidth; // someView.size.width for example 
CGFloat newHeight = whateverYourDesiredHeight; // someView.size.height for example 

CGSize newSize  = CGSizeMake(newWidth, newHeight); 

UIGraphicsBeginImageContext(newSize); 

[yourLargeImage drawInRect:CGRectMake(0, 0, newWidth, newHeight)]; 
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 


return newImage; 

그래서이 원하는 폭과 높이 (어쩌면 크기에 기반 어쩌면 화면 크기, 어쩌면 하드 코딩 된 크기를 점점 UIView) 및 해당 크기의 컨텍스트에서 이미지를 다시 그리기.

~ 행운

편집 : 내가 당신의 욕망을 오해 할 수있다 나에게 발생하므로 (다른 사람이 말했듯이) 나는 또한있는 UIImageView 당신이에 맞게하자의 이미지에 대한 속성을 가지고 있음을 지적합니다 크기, 채우기 비율, 종횡비 유지 등

관련 문제