gpt4 book ai didi

ios - 这是为性能设置属性的首选方式

转载 作者:搜寻专家 更新时间:2023-11-01 07:26:26 24 4
gpt4 key购买 nike

最近我开始使用 Swift 进行 IOS 开发。我看到有两种方法可以设置 UI 元素的某些属性:

  1. 使用“实用工具 > 属性检查器”
  2. ViewController 中覆盖 viewDidLoad 函数(例如 self.actionLabel.textAlignment = .Center)

所以问题是:

  • 就性能而言,哪种方式更适合设置属性值?
  • 如果通过“Utilities > Attributes inspector”设置属性,它存储在哪个文件中?

可能对于简单的应用程序,您使用哪种方式没有意义,但我认为在大型应用程序中可能会有轻微或相当大的差异。提前致谢!

最佳答案

Which way is preferred to set attribute value in terms of performance?

我不确定哪个本身更快。尽管我相当确信您的界面构建器设置已加载到您的初始 View Controller 之前。这会导致您的 Interface Builder 设置首先加载,然后您的编程设置加载(这将覆盖您的 Interface Builder 设置)。

查看这篇文章: How does XCode load the main storyboard?

If attribute set via "Utilities > Attributes inspector" in which file does it stored?

在文本编辑器中打开您的 Main.storyboard,您会看到所有设置都直接存储在 XML 中:

<!-- started from random node -->
<rect key="frame" x="82" y="479" width="211" height="51"/>
<color key="backgroundColor" red="0.17207773850489261" green="0.46615564923228975" blue="0.77629813762626265" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="width" constant="211" id="S1M-Vg-xbE"/>
<constraint firstAttribute="height" constant="51" id="nr7-Cq-G9C"/>
</constraints>
<fontDescription key="fontDescription" name="AvenirNext-Medium" family="Avenir Next" pointSize="21"/>
<state key="normal" title="Login">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="handleLoginTapped:" destination="dtF-AM-7P4" eventType="touchUpInside" id="iVh-kl-1Hl"/>
</connections>
</button>
<imageView userInteractionEnabled="NO" alpha="0.10000000000000001" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="question" translatesAutoresizingMaskIntoConstraints="NO" id="a1j-ZC-tn9">
<rect key="frame" x="162" y="567" width="50" height="50"/>
<constraints>
<constraint firstAttribute="width" constant="50" id="PLN-f0-vSm"/>
<constraint firstAttribute="height" constant="50" id="Uga-aV-5p4"/>
</constraints>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="wra_retina-2" translatesAutoresizingMaskIntoConstraints="NO" id="qkc-Mg-pmQ">
<rect key="frame" x="46" y="20" width="282" height="144"/>
<constraints>
<constraint firstAttribute="height" constant="144" id="OjZ-Nw-qwL"/>
</constraints>
</imageView>

<!-- And on, and on, and on it goes -->

期待有关此问题的其他答案。

关于ios - 这是为性能设置属性的首选方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35806948/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com