两者都可以申请吗stroke and fill与NSAttributedString
and a UILabel
?
是的,关键是要申请Negative的价值NSStrokeWidthAttributeName
如果该值为正数,您将只能看到描边而看不到填充。
Objective-C:
self.label.attributedText=[[NSAttributedString alloc]
initWithString:@"string to both stroke and fill"
attributes:@{
NSStrokeWidthAttributeName: @-3.0,
NSStrokeColorAttributeName:[UIColor yellowColor],
NSForegroundColorAttributeName:[UIColor redColor]
}
];
感谢下面的@cacau:另请参阅技术问答 QA1531 https://developer.apple.com/library/mac/qa/qa1531/_index.html
Swift 4版本:
let attributes: [NSAttributedStringKey : Any] = [.strokeWidth: -3.0,
.strokeColor: UIColor.yellow,
.foregroundColor: UIColor.red]
label.attributedText = NSAttributedString(string: text, attributes: attributes)
斯威夫特 5.1版本:
let attributes: [NSAttributedString.Key : Any] = [.strokeWidth: -3.0,
.strokeColor: UIColor.yellow,
.foregroundColor: UIColor.red]
label.attributedText = NSAttributedString(string: text, attributes: attributes)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)