2

に追加しようとしUIImageていUIViewます。ビュー rect を定義したように、イメージはビューのサイズとまったく同じです。どういうわけか、画像がより広く、より高く表示されていることがわかります(引き伸ばされています)。ビューで画像サイズが変更されるのはなぜですか?

UIImage *strip=[UIImage imageNamed:@"albumStrip.png"];
    UIImageView *imageView=[[UIImageView alloc]initWithImage:strip];
     UIView * aView =  [ [UIView alloc] initWithFrame:CGRectMake(0.03*winSize.width, 0.85*winSize.height , 0.95*winSize.width, winSize.width/10)  ];
    aView.backgroundColor = [UIColor whiteColor];
    aView.tag  = 31000;
    aView.layer.cornerRadius=1;
    [aView addSubview:imageView];

編集:私の画像が640x960であることがわかります。iPhone4の場合、UIImageがそれを取得して係数2で分割する方法を知らない可能性はありますか?

4

3 に答える 3

1

もちろん、画像は引き伸ばされ、ビューに表示できません。そのフレームは UIView のサイズよりもはるかに大きいためです。UIImageView のフレームを UIView と同じサイズに設定し、サブビューとして追加する必要があります。

UIImage *strip=[UIImage imageNamed:@"albumStrip.png"];
CGRect frame = CGRectMake(0.03*winSize.width, 0.85*winSize.height , 0.95*winSize.width, winSize.width/10);
// create the uiimageView with the same frame size as its parentView.
UIImageView *imageView=[[UIImageView alloc] initWithFrame:frame];
// set the image
imageView.image = strip;
// create the view with the same frame
UIView * aView =  [ [UIView alloc] initWithFrame:frame];
aView.backgroundColor = [UIColor whiteColor];
aView.tag  = 31000;
aView.layer.cornerRadius=1;
[aView addSubview:imageView];

もちろん、uiimageview のサイズを小さくすることができれば ;)

于 2013-04-29T09:51:06.420 に答える