简体   繁体   中英

UIImageView Ignores AutoLayout Constraints in UITableViewCell

I'm having a problem with a UIImageView inside of a UITableViewCell when using autolayout. Specifically I'd like to have the image separated from the edges (20pt) , with a strict size(50pt) and so I have defined this: imageview to top = leading to edgeview = 20 height = width = 50

在此输入图像描述

What i find is that the imageview completely ignores its constraints(sorry about the scary smiley, it's what google images gave me). Naturally my desired layout would have more content, but regardless of whether that content is present the effect is the same.

在此输入图像描述

The setup for the project is as follows: Make a single view app Add a table view, connect the data source and write boilerplate to make at least one cell create a tableviewcell with nib, add an imageview to the tableviewcell constraints to top/leading (10 works, with a height of 20) set an image in the imageview so you can see it at runtime

I feel like that should be sufficient, but it seems not to be working, am I missing something silly? For comparison this same setup causes no problem without a tableview, the imageview behaves just the way expected

事实证明我错过了保持Anna版本工作的一步,我已经将UIImageView与一个名为imageView的属性连接起来(覆盖了UITableViewCell的默认属性),显然超类中的约束比我添加的更强。

I couldn't quite get this to work myself, but I think you'll get it if you try some of the things in here:

Using Auto Layout in UITableView for dynamic cell layouts & variable row heights

I think that it doesn't ignore it.Your setup is correct. You just have to stop drawing outside image view. Check this on ImageView: Clip Subviews ->enabled. Choose also good View fill mode: Scale To Fill or Aspect Fit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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