Ios UIImageView没有';不要以编程方式更改维度
如何以编程方式调整在序列图像板文件中创建的UIImageView的尺寸,以匹配特定图像的尺寸?将UIImageView的帧或边界设置为所选图像的帧或边界不会更改Xcode iOS模拟器中imageView的大小。我研究了许多其他类似的问题,并尝试了它们的答案,但迄今为止,它们给出的解决方案似乎都不起作用 以下是用于尝试调整UIImageView大小的代码:Ios UIImageView没有';不要以编程方式更改维度,ios,uiimageview,uiimage,autolayout,Ios,Uiimageview,Uiimage,Autolayout,如何以编程方式调整在序列图像板文件中创建的UIImageView的尺寸,以匹配特定图像的尺寸?将UIImageView的帧或边界设置为所选图像的帧或边界不会更改Xcode iOS模拟器中imageView的大小。我研究了许多其他类似的问题,并尝试了它们的答案,但迄今为止,它们给出的解决方案似乎都不起作用 以下是用于尝试调整UIImageView大小的代码: -(void)viewWillAppear:(BOOL)animated{ //Get selected image UII
-(void)viewWillAppear:(BOOL)animated{
//Get selected image
UIImage *selectedImage=[UIImage imageNamed:selectedItem.pictureName];
//Set imageView's image to selected image
imageView.image=selectedImage;
//Make new frame with dimensions of selected image and same origin
CGRect newImageViewFrame=CGRectMake(imageView.frame.origin.x,imageView.frame.origin.y,selectedImage.size.width,selectedImage.size.height);
//Set imageView's frame to match that of the newly created frame
imageView.frame=newImageViewFrame;
[super viewWillAppear:animated];
}
imageView正确调整大小的唯一方法是将静态imageView替换为以编程方式创建的imageView,以匹配所选图像的帧。奇怪的是,当从头开始创建一个新的UIImageView时,这种方法会起作用,但在尝试调整现有UIImageView的大小时却不会起作用
我的项目当前正在使用AutoLayout,但我尚未向相对UIImageView添加任何约束。这可能是问题的根源吗
我的项目当前正在使用AutoLayout,但我尚未向相对UIImageView添加任何约束。这可能是问题的根源吗
对。不指定约束时,将自动获得“固定框架”约束。图像视图的约束如下所示:
<NSIBPrototypingLayoutConstraint:0x7f95a943bad0 'IB auto generated at build time for view with fixed frame' H:|-(87)-[UIImageView:0x7f95a9b112b0](LTR) (Names: '|':UIView:0x7f95a974e7c0 )>,
<NSIBPrototypingLayoutConstraint:0x7f95a943bfe0 'IB auto generated at build time for view with fixed frame' V:|-(217.5)-[UIImageView:0x7f95a9b112b0] (Names: '|':UIView:0x7f95a974e7c0 )>,
<NSIBPrototypingLayoutConstraint:0x7f95a943c030 'IB auto generated at build time for view with fixed frame' H:[UIImageView:0x7f95a9b112b0(146)]>,
<NSIBPrototypingLayoutConstraint:0x7f95a943c080 'IB auto generated at build time for view with fixed frame' V:[UIImageView:0x7f95a9b112b0(132)]>,
,
,
,
,
因此,当重新应用固定框架约束时,尝试修改框架的内容将被覆盖
您需要做的是建立水平和垂直位置约束。执行此操作后,将不再获得固定框架约束。由于您没有限制大小,它将由intrinsicContentSize
属性决定,该属性将是图像的大小
还有一个细节是,如果没有在情节提要中设置图像,则需要在“大小检查器”中指定占位符固有内容大小,否则会在IB中出现缺少约束的错误
我的项目当前正在使用AutoLayout,但我尚未向相对UIImageView添加任何约束。这可能是问题的根源吗
对。不指定约束时,将自动获得“固定框架”约束。图像视图的约束如下所示:
<NSIBPrototypingLayoutConstraint:0x7f95a943bad0 'IB auto generated at build time for view with fixed frame' H:|-(87)-[UIImageView:0x7f95a9b112b0](LTR) (Names: '|':UIView:0x7f95a974e7c0 )>,
<NSIBPrototypingLayoutConstraint:0x7f95a943bfe0 'IB auto generated at build time for view with fixed frame' V:|-(217.5)-[UIImageView:0x7f95a9b112b0] (Names: '|':UIView:0x7f95a974e7c0 )>,
<NSIBPrototypingLayoutConstraint:0x7f95a943c030 'IB auto generated at build time for view with fixed frame' H:[UIImageView:0x7f95a9b112b0(146)]>,
<NSIBPrototypingLayoutConstraint:0x7f95a943c080 'IB auto generated at build time for view with fixed frame' V:[UIImageView:0x7f95a9b112b0(132)]>,
,
,
,
,
因此,当重新应用固定框架约束时,尝试修改框架的内容将被覆盖
您需要做的是建立水平和垂直位置约束。执行此操作后,将不再获得固定框架约束。由于您没有限制大小,它将由intrinsicContentSize
属性决定,该属性将是图像的大小
还有一个细节是,如果没有在情节提要中设置图像,则需要在“大小检查器”中指定占位符固有内容大小,否则会在IB中出现缺少约束的错误
我的项目当前正在使用AutoLayout,但我尚未向相对UIImageView添加任何约束。这可能是问题的根源吗
对。不指定约束时,将自动获得“固定框架”约束。图像视图的约束如下所示:
<NSIBPrototypingLayoutConstraint:0x7f95a943bad0 'IB auto generated at build time for view with fixed frame' H:|-(87)-[UIImageView:0x7f95a9b112b0](LTR) (Names: '|':UIView:0x7f95a974e7c0 )>,
<NSIBPrototypingLayoutConstraint:0x7f95a943bfe0 'IB auto generated at build time for view with fixed frame' V:|-(217.5)-[UIImageView:0x7f95a9b112b0] (Names: '|':UIView:0x7f95a974e7c0 )>,
<NSIBPrototypingLayoutConstraint:0x7f95a943c030 'IB auto generated at build time for view with fixed frame' H:[UIImageView:0x7f95a9b112b0(146)]>,
<NSIBPrototypingLayoutConstraint:0x7f95a943c080 'IB auto generated at build time for view with fixed frame' V:[UIImageView:0x7f95a9b112b0(132)]>,
,
,
,
,
因此,当重新应用固定框架约束时,尝试修改框架的内容将被覆盖
您需要做的是建立水平和垂直位置约束。执行此操作后,将不再获得固定框架约束。由于您没有限制大小,它将由intrinsicContentSize
属性决定,该属性将是图像的大小
还有一个细节是,如果没有在情节提要中设置图像,则需要在“大小检查器”中指定占位符固有内容大小,否则会在IB中出现缺少约束的错误
我的项目当前正在使用AutoLayout,但我尚未向相对UIImageView添加任何约束。这可能是问题的根源吗
对。不指定约束时,将自动获得“固定框架”约束。图像视图的约束如下所示:
<NSIBPrototypingLayoutConstraint:0x7f95a943bad0 'IB auto generated at build time for view with fixed frame' H:|-(87)-[UIImageView:0x7f95a9b112b0](LTR) (Names: '|':UIView:0x7f95a974e7c0 )>,
<NSIBPrototypingLayoutConstraint:0x7f95a943bfe0 'IB auto generated at build time for view with fixed frame' V:|-(217.5)-[UIImageView:0x7f95a9b112b0] (Names: '|':UIView:0x7f95a974e7c0 )>,
<NSIBPrototypingLayoutConstraint:0x7f95a943c030 'IB auto generated at build time for view with fixed frame' H:[UIImageView:0x7f95a9b112b0(146)]>,
<NSIBPrototypingLayoutConstraint:0x7f95a943c080 'IB auto generated at build time for view with fixed frame' V:[UIImageView:0x7f95a9b112b0(132)]>,
,
,
,
,
因此,当重新应用固定框架约束时,尝试修改框架的内容将被覆盖
您需要做的是建立水平和垂直位置约束。执行此操作后,将不再获得固定框架约束。由于您没有限制大小,它将由intrinsicContentSize
属性决定,该属性将是图像的大小
还有一个细节是,如果您没有在情节提要中设置图像,则需要在大小检查器中指定占位符固有内容大小,否则在IB中会出现缺少约束的错误。图像视图的内容模式设置为什么?您是否已尝试设置父视图的视图。clipsToBounds=是?您确定已将XIB中的ImageView正确连接到IBOutlet?我已尝试这两种方法
SelecteImage.clipsToBounds=是
和选择图像。contentMode=ui视图contentmodescaleaspectfit代码>,但两者似乎都没有任何效果。我假设imageView连接正确,因为故事板显示了selectedImage
和参考插座下的ViewController之间的连接,并且ViewController.h
中selectedImage
旁边的圆圈被着色。图像视图的内容模式设置为什么?您是否已尝试设置父视图的视图。clipsToBounds=是?您确定已将XIB中的ImageView正确连接到IBOutlet?我已尝试这两种方法SelecteImage.clipsToBounds=是
和选择图像。contentMode=ui视图contentmodescaleaspectfit代码>,但两者似乎都没有任何效果。我想