<tfoot id='0TAgu'></tfoot>

    <small id='0TAgu'></small><noframes id='0TAgu'>

  • <i id='0TAgu'><tr id='0TAgu'><dt id='0TAgu'><q id='0TAgu'><span id='0TAgu'><b id='0TAgu'><form id='0TAgu'><ins id='0TAgu'></ins><ul id='0TAgu'></ul><sub id='0TAgu'></sub></form><legend id='0TAgu'></legend><bdo id='0TAgu'><pre id='0TAgu'><center id='0TAgu'></center></pre></bdo></b><th id='0TAgu'></th></span></q></dt></tr></i><div id='0TAgu'><tfoot id='0TAgu'></tfoot><dl id='0TAgu'><fieldset id='0TAgu'></fieldset></dl></div>
    1. <legend id='0TAgu'><style id='0TAgu'><dir id='0TAgu'><q id='0TAgu'></q></dir></style></legend>
      • <bdo id='0TAgu'></bdo><ul id='0TAgu'></ul>

        使用自动布局、IB 和字体大小时表头视图高度错误

        table header view height is wrong when using auto layout, IB, and font sizes(使用自动布局、IB 和字体大小时表头视图高度错误)

            <small id='aYbIH'></small><noframes id='aYbIH'>

            • <bdo id='aYbIH'></bdo><ul id='aYbIH'></ul>

                <i id='aYbIH'><tr id='aYbIH'><dt id='aYbIH'><q id='aYbIH'><span id='aYbIH'><b id='aYbIH'><form id='aYbIH'><ins id='aYbIH'></ins><ul id='aYbIH'></ul><sub id='aYbIH'></sub></form><legend id='aYbIH'></legend><bdo id='aYbIH'><pre id='aYbIH'><center id='aYbIH'></center></pre></bdo></b><th id='aYbIH'></th></span></q></dt></tr></i><div id='aYbIH'><tfoot id='aYbIH'></tfoot><dl id='aYbIH'><fieldset id='aYbIH'></fieldset></dl></div>
                <tfoot id='aYbIH'></tfoot>
                  <tbody id='aYbIH'></tbody>

                  <legend id='aYbIH'><style id='aYbIH'><dir id='aYbIH'><q id='aYbIH'></q></dir></style></legend>
                  本文介绍了使用自动布局、IB 和字体大小时表头视图高度错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试为我的 uiTableView 创建一个标题视图(不是部分标题,我已经有了这些.)我已经在界面生成器中设置了一个 XIB.所有的连接都连接好了,而且运行得很漂亮……除了桌子没有给它足够的空间!我的问题是表格的顶部与表格的标题有一点重叠.

                  I am trying to create a header view for my uiTableView (not a section header, I already have those.) I have set up an XIB in interface builder. All the connections are hooked up and it runs beautifully... except the table doesn't give it enough room! My problem is that the top of the table overlaps the table's header by a little.

                  我的 XIB 设置了所有按钮的 autlayout,IB 很高兴约束不会冲突/模棱两可.视图设置为自由格式大小,在我的情况下最终为 320 x 471.然后在视图的约束中,我为相同的视图设置了固有大小.

                  My XIB is setup with autlayout for all the buttons, and IB is happy that the constraints don't conflict / ambiguous. The view is set to Freeform size, which in my case ended up being 320 x 471. Then in constraints for the view, I set an intrinsic size for the view of the same.

                  现在这与我的桌子完美搭配.一切看起来都很棒.但是,如果我使用代码手动更改标题视图中的任何字体,布局会使视图变大,并最终出现在我的表格下方.

                  Now this works perfectly with my table. Everything looks great. But if I manually change any of the fonts in the header view with code, the layout makes the view bigger, and it ends up underneath my table.

                  在设置字体和大小后如何让 tableviewcontroller 为标题视图留出足够的空间?我希望我的解释是有意义的.

                  Any ideas how to get the tableviewcontroller to leave enough room for the header view after setting fonts and sizes? I hope I've made sense explaining this.

                  推荐答案

                  注意:可以在此处找到 Swift 3+ 版本:https://gist.github.com/marcoarment/1105553afba6b4900c10#gistcomment-1933639

                  Note: A Swift 3+ version can be found here: https://gist.github.com/marcoarment/1105553afba6b4900c10#gistcomment-1933639

                  这个想法是在 systemLayoutSizeFittingSize:targetSize 的帮助下计算标题的高度.

                  The idea is to calculate header's height with help of systemLayoutSizeFittingSize:targetSize.

                  返回满足其约束的视图的大小.考虑所有约束,确定视图的最佳大小持有及其子视图的那些.

                  Returns the size of the view that satisfies the constraints it holds. Determines the best size of the view considering all constraints it holds and those of its subviews.

                  更改表头高度后,需要重新分配 tableHeaderView 属性来调整表格单元格.

                  After changing header's height it is necessary to reassign tableHeaderView property to adjust table cells.

                  基于此答案:在 UITableView 中使用自动布局进行动态单元格布局 &可变行高

                  - (void)sizeHeaderToFit
                  {
                      UIView *header = self.tableView.tableHeaderView;
                  
                      [header setNeedsLayout];
                      [header layoutIfNeeded];
                  
                      CGFloat height = [header systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
                      CGRect frame = header.frame;
                  
                      frame.size.height = height;
                      header.frame = frame;
                  
                      self.tableView.tableHeaderView = header;
                  }
                  

                  这篇关于使用自动布局、IB 和字体大小时表头视图高度错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  iOS AutoLayout - get frame size width(iOS AutoLayout - 获取帧大小宽度)
                  Auto layout constraints issue on iOS7 in UITableViewCell(UITableViewCell中iOS7上的自动布局约束问题)
                  How to resize superview to fit all subviews with autolayout?(如何调整超级视图的大小以适应所有具有自动布局的子视图?)
                  Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5(自动布局中的弹簧:在 Xcode 5 中使用约束均匀分布视图)
                  reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling(具有动态单元格高度的 UITableView 的 reloadData() 导致跳跃滚动)
                  What is NSLayoutConstraint quot;UIView-Encapsulated-Layout-Heightquot; and how should I go about forcing it to recalculate cleanly?(什么是 NSLayoutConstraint“UIView-Encapsulated-Layout-Height?我应该如何强制它干净地重新计算?) - IT屋-程序员

                      <tbody id='HC2JJ'></tbody>
                    • <legend id='HC2JJ'><style id='HC2JJ'><dir id='HC2JJ'><q id='HC2JJ'></q></dir></style></legend>
                      • <bdo id='HC2JJ'></bdo><ul id='HC2JJ'></ul>

                          <small id='HC2JJ'></small><noframes id='HC2JJ'>

                        1. <i id='HC2JJ'><tr id='HC2JJ'><dt id='HC2JJ'><q id='HC2JJ'><span id='HC2JJ'><b id='HC2JJ'><form id='HC2JJ'><ins id='HC2JJ'></ins><ul id='HC2JJ'></ul><sub id='HC2JJ'></sub></form><legend id='HC2JJ'></legend><bdo id='HC2JJ'><pre id='HC2JJ'><center id='HC2JJ'></center></pre></bdo></b><th id='HC2JJ'></th></span></q></dt></tr></i><div id='HC2JJ'><tfoot id='HC2JJ'></tfoot><dl id='HC2JJ'><fieldset id='HC2JJ'></fieldset></dl></div>
                          1. <tfoot id='HC2JJ'></tfoot>