[英]How can I create a label text with shadow?
I'm trying to create a label text with a shadow created automatically by the system. 我正在尝试使用系统自动创建的阴影创建标签文本。 In iOS I know that you can use an Attributed style for the label, but in OS XI can't find this option. 在iOS中,我知道可以为标签使用属性样式,但在OS XI中找不到此选项。 Could you help? 你能帮忙吗?
You can do that with Core Animation (aka CALayer
). 您可以使用Core Animation(aka CALayer
)做到这一点。 Views in iOS are layer-backed by default, but NSView
on Mac OS X are much older and requires you to turn on layer manually. 默认情况下,iOS中的视图具有图层支持,但Mac OS X上的NSView
较旧,需要您手动打开图层。
The easiest way is to go to the View Effects Inspector ( Cmd + Alt + 8
): 最简单的方法是转到View Effects Inspector( Cmd + Alt + 8
):
If you want to add the shadow programmatically: 如果要以编程方式添加阴影:
override func awakeFromNib() {
let shadow = NSShadow()
shadow.shadowOffset = NSMakeSize(5,5)
shadow.shadowBlurRadius = 5
shadow.shadowColor = NSColor.blackColor()
myLabel.superview?.wantsLayer = true
myLabel.shadow = shadow
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.