Rightpoint / BonMot

Beautiful, easy attributed strings in Swift
MIT License
3.56k stars 197 forks source link

how can we add shadow(NSAttributedStringKey.shadow) to stringStyle? #314

Closed SLboat closed 6 years ago

SLboat commented 6 years ago

the orgin nsattributestring code should like this,i cant found any bonmot way to make the shadow

let attributedStringShadow = NSShadow()
attributedStringShadow.shadowOffset = NSMakeSize(0.0,0.0)
attributedStringShadow.shadowBlurRadius = 5.0
attributedStringShadow.shadowColor = NSColor(red:0.0, green:0.0, blue:0.0, alpha:0.333)

let attributedString = NSAttributedString(string: "Hello Worldas", attributes:[NSAttributedStringKey.foregroundColor:NSColor.black,NSAttributedStringKey.shadow:attributedStringShadow,NSAttributedStringKey.font:NSFont(name:"Helvetica", size:24.0)!])
ZevEisenberg commented 6 years ago

@SLboat you should be able to do it like this:

let style = StringStyle(
    .color(exampleColor),
    .font(exampleFont),
    .extraAttributes([
        .shadow: attributedStringShadow // the shadow from your example
    ])
)

It would be great to add support for shadow natively in BonMot. Maybe this is something we'll add in the future, now that we know someone is using it. But that's why we added extraAttributes - so you can use all supported attributes, even ones we haven't added support for yet.

Let me know if this works for you!

SLboat commented 6 years ago

@ZevEisenberg oh!how a great work! thank you!!!

SLboat commented 6 years ago

@ZevEisenberg i want share this. shadowBlurRadius is a very cool effect in a device:)it's like bold,but mush beautiful. slboat-mac-screen 2017-12-13 16 55 34