简体   繁体   English

使用不同的模式,如“Scale To Fill”,“Aspect Fit”,“Aspect Fill”来在UITableViewCell中使用UIImageView

[英]Use of different mode like “Scale To Fill”,“Aspect Fit”,“”Aspect Fill" to handell UIImageView inside UITableViewCell

I have used UIImageView inside the UITableViewCell and it will fill the contentView.I have try different mode like "Scale To Fill","Aspect Fit",""Aspect Fill" to handell UIImageView inside UITableViewCell. UIImageView inside UITableViewCell is running out of the screen in Aspect Fill. I have set constraints for the image as shown below 我在UITableViewCell使用了UIImageView ,它将填充contentView。我尝试了不同的模式,如“Scale To Fill”,“Aspect Fit”,“Aspect Fill”到UITableViewCell里面的UIImageView.UITmageView里面的UIImageView已经用完了Aspect Fill中的屏幕。我为图像设置了约束,如下所示 在此输入图像描述

It works fine as below 它工作正常如下

在此输入图像描述

But when image size is too large it shows problem as below that it goes outside the cell boundary 但是当图像尺寸太大时,它会显示出下面的问题,即它超出了单元边界

在此输入图像描述

I have use Aspect Fill as shown below image 我使用了Aspect Fill ,如下图所示

在此输入图像描述

when I use Aspect Fit I got this problem 当我使用Aspect Fit遇到了这个问题

在此输入图像描述

When I use Scale To Fill I got this problem 当我使用Scale To Fill我遇到了这个问题

在此输入图像描述

In Aspect Fit and Scale To Fill I got margin in left and right as shown above Aspect FitScale To Fill中,如左图所示,左右边距为边距

below link doesnt address my problem so its not duplicate 下面的链接不解决我的问题所以它不重复

UIImageView inside UITableViewCell does not get updated UITableViewCell中的UIImageView没有得到更新

Resizing UIImageView inside a UITableViewCell 在UITableViewCell中调整UIImageView的大小

iOS 8 - AutoLayout issue - UIImageView inside UITableViewCell ignoring width constraints iOS 8 - AutoLayout问题 - UITableViewCell内的UIImageView忽略宽度约束

You have an option named Clip subviews on your table view cell. 您在表格视图单元格上有一个名为Clip subviews的选项。 Check that it's activated, and it should be good. 检查它是否已激活,它应该是好的。

As per your description Your constraints are all set correct. 根据您的描述您的约束都设置正确。

Aspect Fill will draw the entire inside the imageView by maintaining the image's aspect ratio. Aspect Fill将通过保持图像的纵横比来绘制imageView内部的整个内容。 If the image is larger than the imageView's dimension the image overflows. 如果图像大于imageView的尺寸,则图像溢出。 In such cases you need to activate the "Clips subview" option in the attribute inspector of your imageView. 在这种情况下,您需要激活imageView的属性检查器中的“剪辑子视图”选项。

Go to your cell's imageView attribute inspector in storyboard/xib. 转到storyboard / xib中单元格的imageView属性检查器。 Under the "Drawing" section choose "Clips subviews" as true. 在“绘图”部分下,选择“剪辑子视图”为true。

This will make the superView clip its subviews. 这将使superView剪辑成为其子视图。 In your case cell's contentView is the superView and imageView the subview. 在您的情况下,单元格的contentView是superView,imageView是子视图。

You need to enable clip subviews property for imageview, cell's contentview and cell. 您需要为imageview,cell的contentview和cell启用剪辑子视图属性。 One more thing, I saw that while you added constraints, you added constraints with margin.. So, remove old constraints and add again new constraints with disabling Constraints to margin.. 还有一件事,我看到你在添加约束时,你添加了带有边距的约束。所以,删除旧约束并再次添加新约束,禁用约束到边距。

Let me know if it helps. 如果有帮助,请告诉我。 :) :)

I guess there is no issue in cell, Its in Tableview. 我猜单元格中没有问题,它在Tableview中。
Set constraints to your Tableview in which this cell is used. 将约束设置为使用此单元格的Tableview
It will work. 它会工作。

Set width and height constraints for UIImageView 设置UIImageView的宽度和高度约束

Remove other constraints and set below constraints to imageview...! 删除其他约束并将下面的约束设置为imageview ...!

UIImageView --> Editor --> Pin --> Width

UIImageView --> Editor --> Pin --> Height

Refer 参考

https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/pin-constraints.html https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/pin-constraints.html

Hope it fix the issue..! 希望它解决问题..!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM