2011-11-14 5 views
3

어떻게 이미지를 가지고 당신이 볼 수있는UIView에서 이미지를 확대 (스케일)하는 방법은 무엇입니까?

내가로드하고 그것을 배치하고는, 그러나, 일부 스케일링이 필요 내 UIView (460분의 320)에 화면을 채우기 위해 스트레칭 할 수 있습니다.

enter image description here

감사합니다! 내가 Shamsiddin의 게시하려면 UIImageView에이 곳으로 스트레칭하는 방법을 알고 크기를 필요 이상으로 내 의견에 말했듯이

CGRect gameArea = CGRectMake(0, 0, 320, 460); 

UIImage *backgroundImage = [UIImage imageNamed:@"green_background.jpg"]; 
UIImageView *myImageView = [[UIImageView alloc] initWithImage:backgroundImage]; 
[myImageView setContentMode:UIViewContentModeScaleToFill]; 

UIView *topView = [[UIView alloc] initWithFrame:gameArea]; 

[topView addSubview:myImageView];  

[[self view] addSubview:topView]; 

답변

0

UIView *view; 
view.ContentMode = UIViewContentModeScaleToFill; 
+0

작동하지 않는 것 같습니다. 위 코드를 게시하십시오. 제발 봐. – JAM

2
CGRect gameArea = CGRectMake(0, 0, 320, 460); 

UIImage *backgroundImage = [UIImage imageNamed:@"green_background.jpg"]; 
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:gameArea]; 
[myImageView setImage:[backgroundImage stretchableImageWithLeftCapWidth:3 topCapHeight:3]]; 
[myImageView setUserInteractionEnabled:YES]; 
[self.view addSubview:myImageView]; 
+2

Shamsiddin 맞아, 제 생각 엔. UIImageView 크기를 설정하는 것을 잊었 기 때문에 스트레칭이되지 않습니다. UIImageView와 동일한 UIView 크기를 설정해야합니다. – HotFudgeSunday

4

보십시오. 여기에 동일한 크기의 UIView 사용하고 있습니다. UIView 코드가 없기 때문에 다른 답변을 추가했습니다. 여기 전체 코드가 있습니다.

// Area of the UIView and UIImageView 
CGRect gameArea = CGRectMake(0, 0, 320, 460); 

// Create UIImageView with Image 
UIImage *backgroundImage = [UIImage imageNamed:@"green_background.jpg"]; 
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:gameArea]; 
[myImageView setImage:[backgroundImage stretchableImageWithLeftCapWidth:3 topCapHeight:3]]; 
[myImageView setUserInteractionEnabled:YES]; 

// Create UIView and insert subview 
UIView *topView = [[UIView alloc] initWithFrame:gameArea]; 
[topView addSubview:myImageView];  
[[self view] addSubview:topView]; 
+0

그것은 나를 위해 일했던 감사합니다! – NightFury

0

난 그냥 내 자신의 iOS5 응용 프로그램 에서이 일을, 내가 동적으로 배경 이미지를 설정하고 그것을 확장해야했습니다. 당신이

UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.frame]; 
[imageview setContentMode:UIViewContentModeScaleAspectFill]; 
[imageview setImage:[UIImage imageNamed:@"Background.png"]]; 
[self.view addSubview:imageview]; 
[self.view sendSubviewToBack:imageview]; 

- (void)viewWillAppear:(BOOL) animated에서이 일을 상상해 그래서 우리는 기본보기의 하위 뷰로 설정하고 그렇지 않은 있도록 뒷면에 밀어 BG 이미지를 추가, 모드를 확장있어 설정, 뷰를 생성 다른 하위보기를 차지하십시오.

이 대답을 수락하십시오.

관련 문제