gpt4 book ai didi

ios - UILabel:纯文本和属性文本有什么区别?

转载 作者:行者123 更新时间:2023-12-04 10:00:14 26 4
gpt4 key购买 nike

我是 iOS 编程的新手,我尝试四处寻找答案,但不知何故无法找到我认为应该是基本问题的答案。

enter image description here

我注意到两者都可以做同样的事情,我可以更改标签名称、设置自定义字体或系统字体并更改字体粗细、字体大小等。所以问题是,如果 Plain 能够做到这些,我为什么以及何时使用 Attributed?

谢谢。

最佳答案

您可以从名称中了解普通和归因之间的区别。

普通 String并按照 Apple docs

String

A Unicode string value is a series of characters, such as "Swift", that forms a collection. Strings in Swift are Unicode correct and locale insensitive, and are designed to be efficient



至于 归属 String允许您使用自定义颜色、字体、下划线、阴影等设置文本范围的格式 Apple Docs

NSAttributedString

A string that has associated attributes (such as visual style, hyperlinks, or accessibility data) for portions of its text.An NSAttributedString object manages character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. An association of characters and their attributes is called an attributed string. The cluster’s two public classes, NSAttributedString and NSMutableAttributedString, declare the programmatic interface for read-only attributed strings and modifiable attributed strings, respectively.



除非你有特定的理由使用 AttributedString ,你几乎可以忘记它的存在。

enter image description here

这里有个好消息 Medium Article在属性字符串上

关于ios - UILabel:纯文本和属性文本有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61846842/

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