简体   繁体   English

如何创建带有阴影的标签文本?

[英]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.

相关问题 如何使用功能更新文本标签? - How can I update text label with a function? 如何制作带有2个标签的自定义UITableViewCell,以便如果标签的文本为空,则另一个填充该空间? - How I can make a custom UITableViewCell with 2 label so if the text of a label is empty the other fills the space? 如何在swift中创建可扩展的文本字段/标签? - How to create an expandable text field/label in swift? 我可以将标签固定在另一个标签内以创建边框吗? - Can I pin a label inside another label to create a border? 阴影到标签 - Shadow to a label 如何使用文本字段警报操作在单独的 UIViewController 上更新 label? - How can I use a text field alert action to update a label on a separate UIViewController? 我无法在Swift 3中使用Timer更改label.text - I Can't Change label.text with Timer in Swift 3 我无法在集合视图单元格中为标签创建出口 - I can't create an outlet for a label in my collection view cell 我怎样才能不断改变标签的价值 - how can I change value of label constantly 如何根据表视图单元格的详细文本标签,将segue设置为与表视图控制器不同的视图控制器? - How can I set a segue to a different view controller from a table view controller, based on the detail text label of the table view cell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM