Ios 如何将特定大小设置为UIImageView

Ios 如何将特定大小设置为UIImageView,ios,objective-c,uiimageview,Ios,Objective C,Uiimageview,我有一只奇怪的虫子。我试图用特定的帧和图像以编程方式初始化UIImageView。我的图像是60x60,但我试图在屏幕上将其调整为30x30,这似乎是不可能的 以下操作正常,但以60x60显示图像: UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]]; [imgView setContentMode:UIViewContentModeScaleAspect

我有一只奇怪的虫子。我试图用特定的帧和图像以编程方式初始化UIImageView。我的图像是60x60,但我试图在屏幕上将其调整为30x30,这似乎是不可能的

以下操作正常,但以60x60显示图像:

 UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
    [imgView setContentMode:UIViewContentModeScaleAspectFit];
//    imgView.frame = CGRectMake(100, 200, 30, 30);
    imgView.center = CGPointMake(pointTouch.x, pointTouch.y);
    [self.view addSubview:imgView];
下面的内容根本没有在屏幕上显示任何内容:

  UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
    [imgView setContentMode:UIViewContentModeScaleAspectFit];
    imgView.frame = CGRectMake(100, 200, 30, 30);
    imgView.center = CGPointMake(pointTouch.x, pointTouch.y);
    [self.view addSubview:imgView];
怎么了

编辑对于那些有相同问题的人,这里是工作代码:

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
imgView.frame = CGRectMake(self.view.bounds.size.width/2, self.view.bounds.size.height/2, 30, 30);
imgView.center = CGPointMake(pointTouch.x, pointTouch.y);
[imgView setContentMode:UIViewContentModeScaleAspectFill];
[self.view addSubview:imgView];

您可以尝试使用设置的帧初始化
UIImageView
,然后设置图像:

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 200, 30, 30)];
[imgView setContentMode:UIViewContentModeScaleAspectFit];
imgView.image = [UIImage imageNamed:@"logo.png"];
imgView.center = CGPointMake(pointTouch.x, pointTouch.y);
[self.view addSubview:imgView];
开始试验

imgView.center = CGPointMake(view.bounds.x/2, view.bounds.y/2);
imgView.bounds = view.bounds; 
看看这是否填充了superview。然后分别尝试
CGPointMake(pointTouch.x,pointTouch.y)
CGPointMake(30,30)

我猜这种行为与关于
frame
有关:

如果transform属性不是标识转换,则此属性的值未定义,因此应忽略


如果您不更改
imgView.center
,它会显示吗?您使用的是自动布局吗?@gWiz:不,不起作用either@ErikKerber:不,我是not@AnthonyGuay尝试设置imgView.backgroundColor=[UIColor GREENCLOR],排除找不到的图像。另外,四重检查您正在添加UIImageView的视图是否未选中“自动布局”复选框(假设它位于故事板或Nib中)。如果启用“自动布局”,则设置框架不会产生任何影响。不起作用。即使我删除了imgView.center=CGPointMake(pointTouch.x,pointTouch.y),屏幕上没有添加任何内容