我想在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提供的格式
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。