如何在swift 3中使用addAttribute和NSRANGE

如何在swift 3中使用addAttribute和NSRANGE,第1张

概述嗨,我正在尝试在 Swift3中使用addAttribute. 我想要只设置粗体IDNAME. 这就是我想要的. let boldUsername = NSMutableAttributedString(string: "IDNAME hi nice 2 meet you :D #HELLOW")// boldUsername.addAttribute(NSFontAt 嗨,我正在尝试在 Swift3中使用addAttribute.

我想要只设置粗体IDname.

这就是我想要的.

let boldUsername = NSMutableAttributedString(string: "IDname hi nice 2 meet you :D #HELLOW")//            boldUsername.addAttribute(NSFontAttributename,value: UIFont(name: "SFUIText-Bold",size: 14)!,range: (boldUsername.string as Nsstring).range(of: " "))            boldUsername.addAttribute(NSFontAttributename,range: NSRange(location: 0,length: 5))

我如何获得IDname的索引,即每次都不同?

– >有没有办法分割空间并获得索引?

你需要做这样的事情.
let personname = "Black"let wholeStr = "\(personname) hi nice 2 meet you :D #HELLOW"let boldUsername = NSMutableAttributedString(string: wholeStr)boldUsername.addAttribute(NSFontAttributename,range: (wholeStr as Nsstring).range(of: personname))
总结

以上是内存溢出为你收集整理的如何在swift 3中使用addAttribute和NSRANGE全部内容,希望文章能够帮你解决如何在swift 3中使用addAttribute和NSRANGE所遇到的程序开发问题。

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

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

原文地址:https://www.54852.com/web/1031896.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存