简体   繁体   English

如何在具有Scale to Fill模式的tableViewHeader中为UIImageView使用固定高度?

[英]How to use a fixed height for UIImageView in a tableViewHeader with Scale to Fill mode?

  • iOS 6+ iOS 6+
  • Using Auto Layout 使用自动布局
  • Table View with Header and Footer because cells in between are static (static cells are only supported in a UITableViewController, not a UITableView in a normal UIViewController..) 带有页眉和页脚的表视图,因为其间的单元格是静态的(静态单元格仅在UITableViewController中支持,而不是普通UIViewController中的UITableView ..)

In IB I set the height of the UIImageView to 140. The image that I load into it is square. 在IB中,我将UIImageView的高度设置为140.我加载到它的图像是方形的。 I want to use scale to fill and see a portion of the image, as long as the entire UIImageView is filled. 我想使用缩放来填充和查看图像的一部分,只要整个UIImageView被填充。 There is no way to use constraints on this header view, not in IB, not programatically (tried). 没有办法在这个标题视图上使用约束,而不是在IB中,而不是以编程方式(尝试过)。

The issue is that probably because of Auto Layout, the UIImageView gets stretched until the image fits entirely in the UIImageView. 问题是可能是因为Auto Layout,UIImageView会被拉伸,直到图像完全适合UIImageView。 In fact the image view is even stretched over the first couple of rows of the table view's body. 实际上,图像视图甚至在表视图主体的前几行上拉伸。

How can I get around this issue? 我该如何解决这个问题?

通过检查IB中的“剪辑子视图”来修复。

尝试使用[UIView setContentMode:]

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

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