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

    <small id='68O6b'></small><noframes id='68O6b'>

  1. <legend id='68O6b'><style id='68O6b'><dir id='68O6b'><q id='68O6b'></q></dir></style></legend>
  2. <tfoot id='68O6b'></tfoot>

      如何使用自动布局将 UILabel 设置为 UICell 宽度的百分比

      How to set a UILabel as a percentage of the width of the UICell with autolayout(如何使用自动布局将 UILabel 设置为 UICell 宽度的百分比)
    1. <i id='rCyfB'><tr id='rCyfB'><dt id='rCyfB'><q id='rCyfB'><span id='rCyfB'><b id='rCyfB'><form id='rCyfB'><ins id='rCyfB'></ins><ul id='rCyfB'></ul><sub id='rCyfB'></sub></form><legend id='rCyfB'></legend><bdo id='rCyfB'><pre id='rCyfB'><center id='rCyfB'></center></pre></bdo></b><th id='rCyfB'></th></span></q></dt></tr></i><div id='rCyfB'><tfoot id='rCyfB'></tfoot><dl id='rCyfB'><fieldset id='rCyfB'></fieldset></dl></div>

        <tbody id='rCyfB'></tbody>

          <legend id='rCyfB'><style id='rCyfB'><dir id='rCyfB'><q id='rCyfB'></q></dir></style></legend>

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

                <bdo id='rCyfB'></bdo><ul id='rCyfB'></ul>
                <tfoot id='rCyfB'></tfoot>
              • 本文介绍了如何使用自动布局将 UILabel 设置为 UICell 宽度的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想知道如何将 UILabel 的宽度设置为单元格总宽度的百分比?我正在使用自动布局.通常我会单击标签并将 EqualsWidth 设置为 parentView,然后调整乘数,因此我将宽度设置为 parentWidth 的百分比.但是使用 InterfaceBuilder 该选项似乎在 Cell 中不可用.

                I'm wondering how to set a UILabel's width expressed as a % of the Cell's total width? I'm using AutoLayout. Normally I would click on the label and set the EqualsWidth to a parentView and then adjust the multiplier so I set the width as a % of the parentWidth. But using InterfaceBuilder that option does not seem to be available within the Cell.

                但是我想知道它可能与设置首选宽度有关:我正在使用 ios8+ 并且已经读到隐式宽度不适用于 ios8?

                However I'm wondering maybe it has something to do with setting the preferred Width: I'm using ios8+ and have read that implicit widths are not available for ios8?

                我希望实现的是标签 1 和标签 3 都是单元格宽度的 15%,标签 2 的前缘和后缘固定在 UIImageView 和标签 3 上,这将允许它根据设备的宽度.

                What I am hoping to achieve is that Label 1 and Label 3 are both 15% the width of the Cell and Label 2 has leading and trailing edges pinned to UIImageView and Label 3 that will allow it to grow and shrink depending on the width of the device.

                推荐答案

                为实现在单元格内设置任何子视图的百分比宽度的目标应该执行的步骤:

                Steps you should do to achieve your goal of setting percentage width of any subview inside cell:

                1. 将 UIView 添加到您的单元格并将其固定到每个边缘 - 我们必须添加自定义容器视图,以便以后能够添加等宽"引脚.

                1. Add UIView to your cell and pin it to every edge - we have to add custom container view in order to be able to add "Widths equally" pin later on.

                将 UILabel 添加到之前添加的 UIView 容器中.假设我们要添加左侧标签,因此添加 3 个引脚:左侧、顶部、底部.

                Add UILabel to previously added UIView container. Lets say we want to add left side label, so add 3 pins to it: left, top, bottom.

                您现在可以看到您的约束设置有错误.所以让我们修复它并添加宽度相等"引脚.在 View Controller Scene 菜单中选择 2 个视图 - 容器和标签.转到 XcodeMenu/Editor/Pin/并选择宽度相等".现在您应该在约束设置中看到没有错误,并且标签应该与容器具有相同的大小.(请注意,有时您必须在设置约束后刷新视图框架,所以如果您看到黄色"警告图标不要害怕,只需点击它即可.

                You can see now that you have error in your constraint setup. So lets fix it and add "Widths equally" pin. Select 2 views in View Controller Scene menu - the container and the label. Go to XcodeMenu/Editor/Pin/ and select "Widths equally". Now you should see no errors in you constraints setup and the label should have same size as the container. (Please note that sometimes you have to refresh frames of your views after setting constraints, so if you see "yellow" warning icon don't be afraid and just click on it).

                现在,如果您有所有限制,我们需要设置实际百分比值.打开选项卡 Size Inspector,单击步骤 3 中添加的约束上的编辑"标题.并将乘数值更改为 0.15 (15%).

                Now if you have all your constraints we need to set actual percentage value. Open tab Size Inspector, click "Edit" title on constraint added in step 3. and change Multiplier value to 0.15 (15%).

                请注意,如果您要使用相同的技术添加标签但右侧,则需要将乘数设置为 6.66 (= 1.00/0.15).

                Please note that, if you would add label using same technique but for right side, then you would need to set Multiplier value to 6.66 (= 1.00 / 0.15).

                干杯!

                这篇关于如何使用自动布局将 UILabel 设置为 UICell 宽度的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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屋-程序员

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

                  1. <small id='BOrlc'></small><noframes id='BOrlc'>

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

                          <tbody id='BOrlc'></tbody>
                        <tfoot id='BOrlc'></tfoot>