我在NSMutableAttributedString上设置阴影,它适用于其他版本的iOS,但不适用于iOS 13,下一个是我的代码
let shadow = NSShadow.init()
shadow.shadowColor = UIColor.red
shadow.shadowBlurRadius = 20
attr.addAttribute(NSAttributedString.Key.shadow, value: shadow, range: NSRange.init(location: 0, length: (text as NSString).length))
它在UILabel attributedText上运行良好,但在iOS13 上的CATextLayer字符串上运行不佳
iOS 14或更高版本的
let shadow = NSShadow.init()
shadow.shadowColor = UIColor.red
shadow.shadowBlurRadius = 20
attr.addAttribute(NSAttributedString.Key.shadow, value: shadow, range: NSRange.init(location: 0, length: (text as NSString).length))
subLayer.string = attr
ios 13或更早版本的
let shadow = NSShadow.init()
shadow.shadowColor = UIColor.red
shadow.shadowBlurRadius = 20
attr.addAttribute(NSAttributedString.Key.shadow, value: shadow, range: NSRange.init(location: 0, length: (text as NSString).length))
subLayer.shadowRadius = 20
subLayer.shadowColor = UIColor.red.cgColor
subLayer.shadowOpacity = 1
subLayer.string = attr