• <bdo id='TXctU'></bdo><ul id='TXctU'></ul>
  • <tfoot id='TXctU'></tfoot>
  • <small id='TXctU'></small><noframes id='TXctU'>

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

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

        动态更新 UILabel 在 UIView 上的位置取决于它们的文本值

        时间:2023-09-09
      1. <legend id='air0R'><style id='air0R'><dir id='air0R'><q id='air0R'></q></dir></style></legend>

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

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

              <bdo id='air0R'></bdo><ul id='air0R'></ul>

                    <tbody id='air0R'></tbody>
                  本文介绍了动态更新 UILabel 在 UIView 上的位置取决于它们的文本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我从网络上获取这些值.如果所有值都来自网络,则此屏幕看起来很酷.

                  I am getting these values from web. This screen if all values came from web which looks cool.

                  在没有数据的情况下,如下所示.

                  And in absence of data it looks like follows.

                  我用过这段代码

                  //Purchasae info
                      {
                          NSInteger heightToDecrease = 0;
                          NSInteger heightToIncrease = 0;
                          // NSInteger LABEL_HEIGHT = 18;
                  
                          maximumSize = CGSizeZero;
                          textSize = CGSizeZero;
                  
                          //purchaseCostLabel
                          heightToDecrease += self.PurchsCostHeightConstrains.constant;
                          maximumSize = CGSizeMake(self.purchaseCostLabel.frame.size.width, 999);
                          textSize = [UtilityHandler textSizeOfString:self.purchaseCostLabel.text font:self.purchaseCostLabel.font maxSize:maximumSize];
                          NSInteger purchaseCostLabelHeight = textSize.height+SPACE_PADDING;
                          self.PurchsCostHeightConstrains.constant = purchaseCostLabelHeight;
                          totalHeightToIncrease += self.PurchsCostHeightConstrains.constant;
                  
                          //insurance
                          heightToDecrease += self.insuranceHeightConstraints.constant;
                          maximumSize = CGSizeMake(self.purchaseInsuranceLabel.frame.size.width, 999);
                          textSize = [UtilityHandler textSizeOfString:self.purchaseInsuranceLabel.text font:self.purchaseInsuranceLabel.font maxSize:maximumSize];
                          NSInteger insCostLabelHeight = textSize.height+SPACE_PADDING;
                          self.insuranceHeightConstraints.constant = insCostLabelHeight;
                          totalHeightToIncrease += self.insuranceHeightConstraints.constant;
                  
                          //shipping
                          heightToDecrease += self.shippingHeightConstarants.constant;
                          maximumSize = CGSizeMake(self.shippingLabel.frame.size.width, 999);
                          textSize = [UtilityHandler textSizeOfString:self.shippingLabel.text font:self.shippingLabel.font maxSize:maximumSize];
                          NSInteger shippingLabelHeight = textSize.height+SPACE_PADDING;
                          self.shippingHeightConstarants.constant = shippingLabelHeight;
                          totalHeightToIncrease += self.shippingHeightConstarants.constant;
                  
                          //conservation
                          heightToDecrease += self.conserVHeightConstraints.constant;
                          maximumSize = CGSizeMake(self.conservationLabel.frame.size.width, 999);
                          textSize = [UtilityHandler textSizeOfString:self.conservationLabel.text font:self.conservationLabel.font maxSize:maximumSize];
                          NSInteger conserLabelHeight = textSize.height+SPACE_PADDING;
                          self.conserVHeightConstraints.constant = conserLabelHeight;
                          totalHeightToIncrease += self.conserVHeightConstraints.constant;
                          //storage
                          heightToDecrease += self.storageHeightConstraints.constant;
                          maximumSize = CGSizeMake(self.storageLabel.frame.size.width, 999);
                          textSize = [UtilityHandler textSizeOfString:self.storageLabel.text font:self.storageLabel.font maxSize:maximumSize];
                          NSInteger storagLabelHeight = textSize.height+SPACE_PADDING;
                          self.storageHeightConstraints.constant = storagLabelHeight;
                          totalHeightToIncrease += self.storageHeightConstraints.constant;
                          //Frameing
                          heightToDecrease += self.framingHeightConstraints.constant;
                          maximumSize = CGSizeMake(self.shippingLabel.frame.size.width, 999);
                          textSize = [UtilityHandler textSizeOfString:self.shippingLabel.text font:self.shippingLabel.font maxSize:maximumSize];
                          NSInteger framLabelHeight = textSize.height+SPACE_PADDING;
                          self.framingHeightConstraints.constant = framLabelHeight;
                          totalHeightToIncrease += self.framingHeightConstraints.constant;
                  
                          // set content view height constraint
                          self.purchaseInformationViewHeightConstraint.constant -= heightToDecrease;
                          // set content view height constraint
                          self.purchaseInformationViewHeightConstraint.constant += heightToIncrease;
                  
                  
                      }
                  

                  那么如何更新标签框架,以便任何标签可以占据空白标签的位置?

                  So how do I update labels frame so if any label can take blank labels' positions?

                  推荐答案

                  为您的标签使用 Storyboard,并且仅使用单个标签将您的标签设置为具有所有 4 个约束,左、右、上、下设置行数 0.它适用于您的文本

                  Use Storyboard for your label and use only single label Set your label to have all 4 constraints, left,right,top,bottom Set number of lines 0. It will work for your text

                  这篇关于动态更新 UILabel 在 UIView 上的位置取决于它们的文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UITableViewCell 子类布局在禁用自动布局的故事板中搞砸了 下一篇:AutoLayout 理解乘数

                  相关文章

                  <tfoot id='4O3gK'></tfoot>

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

                    <bdo id='4O3gK'></bdo><ul id='4O3gK'></ul>
                    1. <small id='4O3gK'></small><noframes id='4O3gK'>