Objective c UIView是否更改图像的大小?

Objective c UIView是否更改图像的大小?,objective-c,Objective C,我正在尝试将UIImage添加到UIView。 图像的大小与视图的大小完全相同——正如我定义的view rect。 不知何故,我看到图像显示得更宽、更高(它被拉伸了)。 为什么我的视图会更改图像大小 UIImage *strip=[UIImage imageNamed:@"albumStrip.png"]; UIImageView *imageView=[[UIImageView alloc]initWithImage:strip]; UIView * aView = [ [

我正在尝试将
UIImage
添加到
UIView
。 图像的大小与视图的大小完全相同——正如我定义的view 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进行分割?

使用

imageView.layer.masksToBounds=YES
这将限制图像的宽度和高度


如果masksToBounds特性设置为“是”,则延伸到其边界之外的层的任何子层都将剪裁到这些边界。在这种情况下,将层视为其子层的窗口;窗口边缘以外的任何东西都将不可见。当masksToBounds为“否”时,不会发生剪切,延伸到层边界之外的任何子层都将整体可见(只要它们不超出任何启用了遮罩的超层的边缘)。

尝试设置UIImageView的ContentMode()


imageView.contentMode=UIViewContentModeScaleAspectFit

当然,您的图像将被拉伸,无法在视图中显示。 因为它的框架比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的大小变小;)

尝试
aview.layer.masksToBounds=YES如何更改视图的内容模式?