2012-04-20 20 views
2

私は本当に配線された問題があり、解決方法はわかりません。私はUIButtonsフレームをアニメーション化しています。アニメーション化するときは、ボタンの画像をボタンと同じサイズに拡大します。それは私のiPhoneシミュレータで何もせずに動作します。しかし、私はそれをiPadのシミュレータで実行すると、画像のサイズは変わりません。いくつかの場所で[[gissaImg1 imageView] setContentMode:UIViewContentModeScaleToFill]コードを追加しましたが、それは役に立ちませんでした。UIButtonイメージのサイズ変更/縮尺を

何が問題なのか、この問題を解決する方法を知っていますか?

//Code to set the image 
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@_small", 
               [[itemsForRound objectAtIndex:[[guessItems objectAtIndex:0] intValue]] valueForKey:@"Name"]]]; 

[self.gissaImg1 setImage:image forState:UIControlStateNormal]; 
[self.gissaImg1 setImage:image forState:UIControlStateHighlighted]; 

//Code to animate button 
CGRect animateToSpot = (isIphone) ? CGRectMake(0, 0, 480, 320) : CGRectMake(0, 0, 1024, 768); 
    [self performSelector:@selector(PlayCorrectSound:) withObject:nil afterDelay:1]; 
    [[gissaImg1 imageView] setContentMode:UIViewContentModeScaleToFill]; 
    [UIView animateWithDuration:1.5 delay:0 options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveLinear) animations:^{ 
     switch (index) { 
      case 0: 
       [[gissaImg1 imageView] setContentMode:UIViewContentModeScaleToFill]; 
       [self.gissaImg1 setFrame:animateToSpot]; 
       [self.view bringSubviewToFront:gissaImg1]; 
       break; 
....... 

答えて

24

setBackgroundImage代わりのsetImageを試してみて、そして画像に何もしません。私はこれが誰かのための助けと思い、最後の行(button.titleEdgeInsets = UIEdgeInsetsMake(0, -imageSize.width, 0, 0);

を削除するには、タイトルを表示したくない場合は、これは

+0

はい、それは役に立ちました。ありがとう – Uffe

+0

それは働く...ありがとう男 – eurica

0
UIImage *thubNailImage=[UIImage imageNamed:@"thumImage"]; 
[button.imageView setContentMode:UIViewContentModeScaleAspectFill]; 
CGSize imageSize=thubNailImage.size; 
[button setImage:thubNailImage forState:UIControlStateNormal]; 
button.titleEdgeInsets = UIEdgeInsetsMake(0, -imageSize.width, 0, 0); 

を助け 希望を(サイズを変更したりsetContentMode)。 :)

関連する問題