24

私は客観的なcに非常に慣れていないので、自分の方向性をつかんでいます。私は本当に簡単なことをしたいのですが、それはかなりの挑戦であることがわかります:

に画像を表示しようとしていますUIImageView。表示している画像が大きいので、サイズに合わせて縮小したいと思いUIImageViewます。表示モードを設定してみましAspectFitたが、画像が元のサイズで表示され、UIImageView. 私のコードは以下の通りです:

- (void)changeImages
{
    UIImage* img11 = nil;

    img11 = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"jpeg"]];

    u11.contentMode = UIViewContentModeScaleAspectFit;
    u11.image = img11;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self changeImages];
}

誰でもこれに光を当てることができますか?

ありがとう!

4

6 に答える 6

32

こんにちは私はこれを試してみます...

- (void)changeImages
{
    UIImage *img11 = [UIImage imageNamed@"dog.jpeg"];

    u11.contentMode = UIViewContentModeScaleAspectFit;
    u11.clipsToBounds = YES;
    [u11 setImage:img11];
}

- (void)viewWillAppear:animated
{
    [super viewWillAppear:animated];

    [self changeImages];
}

これにより、画像がimageView内に収まるように画像が拡大縮小(拡大または縮小)されます。clipToBoundsを設定する必要はありませんが、imageViewのフレームの外側に画像が表示されなくなります。

HTH。

于 2012-09-23T14:02:37.300 に答える
4
CGSize size=CGSizeMake(79, 84);//set the width and height
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0,0,size.width,size.height)];
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
//here is the scaled image which has been changed to the size specified
UIGraphicsEndImageContext();

これは確実に機能し、QuartzCore FrameWork をインポートすることを忘れないでください。

楽しいコーディングを(^_^)...

于 2013-02-23T05:19:21.110 に答える
0

私は次のことを行い、モードをデフォルト値の「Scale to fill」から「aspect fill」に変更するのに役立ちました

次のようにコード行を追加します(セル構成で行いました):

cell.photo.clipsToBounds = true
于 2016-07-15T20:01:43.203 に答える