Cue
Cue

Reputation: 3092

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 X I can't find this option. Could you help?

Upvotes: 0

Views: 647

Answers (1)

Code Different
Code Different

Reputation: 93181

You can do that with Core Animation (a.k.a. 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.

The easiest way is to go to the View Effects Inspector (Cmd + Alt + 8):

View Effects Inspector

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
}

Upvotes: 2

Related Questions