如何在Swift中附加带有属性字符串的归类文本字符串

如何在Swift中附加带有属性字符串的归类文本字符串,第1张

概述我想在Swift中附加一个归因文本和另一个归因文本。请提供任何示例代码,用于在Swift中添加两个归属的String的 *** 作。 使用NSMutableAttributedString 小例子 let yourAttributes = [NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName: UIFont.s 我想在Swift中附加一个归因文本和另一个归因文本。请提供任何示例代码,用于在Swift中添加两个归属的String的 *** 作。 使用NSMutableAttributedString

小例子

let yourAttributes = [NSForegroundcolorAttributename: UIcolor.blackcolor(),NSFontAttributename: UIFont.systemFontOfSize(15)]let yourOtherAttributes = [NSForegroundcolorAttributename: UIcolor.redcolor(),NSFontAttributename: UIFont.systemFontOfSize(25)]let partOne = NSMutableAttributedString(string: "This is an example ",attributes: yourAttributes)let partTwo = NSMutableAttributedString(string: "for the combination of Attributed String!",attributes: yourOtherAttributes)let combination = NSMutableAttributedString()combination.appendAttributedString(partOne)combination.appendAttributedString(partTwo)

Swift 3

combination.append(partOne)combination.append(partTwo)

然后,组合是您的最终字符串,其中包含由您的属性和yourOtherAttributes提供的格式

总结

以上是内存溢出为你收集整理的如何在Swift中附加带有属性字符串的归类文本字符串全部内容,希望文章能够帮你解决如何在Swift中附加带有属性字符串的归类文本字符串所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1052548.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存