Questions tagged [nsshadow]

An NSShadow object encapsulates the attributes used to create a drop shadow during drawing operations. Available in iOS 6.0 and later in UIKit and available in OS X v10.3 and later in AppKit.

An NSShadow object encapsulates the attributes used to create a drop shadow during drawing operations.

Shadows are always drawn in the default user coordinate space, regardless of any transformations applied to that space. This means that rotations, translations and other transformations of the current transformation matrix (the CTM) do not affect the resulting shadow. Another way to think about this is that changes to the CTM do not move or change the apparent position of the shadow’s light source.

There are two positional parameters for a shadow: an x-offset and a y-offset. These values are expressed using a single size data type (CGSize on iOS, NSSize on OS X) and using the units of the default user coordinate space. Positive values for these offsets extend up and to the right.

In addition to its positional parameters, a shadow also contains a blur radius, which specifies how much a drawn object's image mask is blurred before it is composited onto the destination. A value of 0 means there is no blur. Larger values give correspondingly larger amounts of blurring.

An NSShadow object may be used in one of two ways. First, it may be set, like a color or a font, in which case its attributes are applied to all content drawn thereafter—or at least until another shadow is applied or a previous graphics state is restored. Second, it may be used as the value for the NSShadowAttributeName text attribute, in which case it is applied to the glyphs corresponding to the characters bearing this attribute.

23 questions
13
votes
2 answers

Custom NSView with rounded corners and drop shadow

I'm trying to create a custom NSView with both rounded corners and a drop shadow. I created an NSView subclass and have the following drawRect: method - (void)drawRect:(NSRect)dirtyRect { NSRect rect = NSMakeRect([self bounds].origin.x + 3,…
Lou Howard
  • 131
  • 1
  • 1
  • 3
6
votes
0 answers

Draw shadow of layer-backed NSView beyond bounds

I'd like to get a custom NSShadow on a borderless NSWindow, and since I'm also applying some animations on the window, I've set up the window's content view to be layer-backed. When applying the NSShadow on the contentView, the shadow is clipped at…
Raffael
  • 1,119
  • 10
  • 20
5
votes
0 answers

CATextLayer ignores NSShadow?

I have a custom UIView that I've created that has several custom UIControl instances which are non-rectangular buttons (instead of using UIButton instances). I am doing this because I need to be able to draw non-rectangular buttons and have them…
mbm29414
  • 11,558
  • 6
  • 56
  • 87
4
votes
1 answer

Custom NSWindow with a custom shadow

I have a NSWindow subclass, looking like this The thing that bothers me is that I would like to alter the shadow. Over a standard window, like Xcode right here, the contrast is a little weak. So I'd like to apply a stronger NSShadow to it. I found…
IluTov
  • 6,807
  • 6
  • 41
  • 103
3
votes
1 answer

Cannot get a drop shadow on multiline nsstring

I'm trying to get multiline text to draw with a drop shadow without using deprecated APIs. It works fine for a single line. The relevant code looks like this: -(void)drawRect:(CGRect)rect { NSMutableParagraphStyle *paragraph = …
Airsource Ltd
  • 32,379
  • 13
  • 71
  • 75
3
votes
3 answers

How to add shadow to NSView

I've spent some time trying to figure out how to add a shadow to an NSView. For now, I am attempting to use the NSShadow class to accomplish this. My code is below. I am attempting to create the shadow in a custom init method in a NSView subclass.…
Jack Humphries
  • 13,056
  • 14
  • 84
  • 125
2
votes
1 answer

Redrawed inset NSShadow on a Custom View using -setClip method

I have and odd problem, related with the answer of this question: Draw an Inset NSShadow and Inset Stroke I use this code into the drawRect method of a custom view. I have exactly this: - (void)drawRect:(NSRect)rect { // Create and fill the…
Jordi Tost
  • 99
  • 1
  • 9
2
votes
0 answers

NSWindow shadow with transparency, how to clip certain area

In our OS X application, we have enabled window shadow by view.window?.hasShadow = true. This will create a fine shadow over NSWindow. We have created a hole in the application by a custom view to see the background through it, via its mask…
2
votes
0 answers

NSShadowAttributeName not working

Can anyone see what is wrong in the following Swift code? func myFunction(color:UIColor) {// Changes the Shadow color on textLabel var attributes = textLabel.attributedText?.attributesAtIndex(0, effectiveRange: nil) let shadow =…
Michel
  • 10,303
  • 17
  • 82
  • 179
2
votes
1 answer

Subclassing an NSScrollView's DocumentView

How can one subclass an NSScrollView's DocumentView in order to do some custom drawing? I need to do some work with NSShadow inside of the scroll view.
John Wells
  • 1,139
  • 1
  • 10
  • 27
2
votes
0 answers

NSShadow in Mountain Lion not showing

I have the strange problem, that I cannot set shadows for my (layer-backed) views anymore since upgrading to 10.8. NSShadow *shadow = [[NSShadow alloc] init]; [shadow setShadowColor:[NSColor darkGrayColor]]; [shadow setShadowOffset:NSMakeSize(0.0,…
1
vote
1 answer

How to make a shadow on iOS13

I set shadow on NSMutableAttributedString, it works on other version of iOS but not iOS 13, the next is my code let shadow = NSShadow.init() shadow.shadowColor = UIColor.red shadow.shadowBlurRadius = 20 …
danfei91
  • 21
  • 5
1
vote
1 answer

NSShadow and paper-curl effect in Desktop

i was playing with some source code from this blog: http://nachbaur.com/blog/fun-shadow-effects-using-custom-calayer-shadowpaths because i wanted to replicate its paper-curl effect with the shadow. But it seems the property shadowPath of CALayer is…
Ernesto
  • 510
  • 3
  • 10
1
vote
1 answer

Swift - Where is shadowOpacity on NSShadow?

I just discovered the unfortunate fact that setting the shadow properties of an NSView's backing layer on macOS does not cause the shadow to render. It seems that this only works for stand-alone layers. I then found out about NSShadow and I gave it…
jeremyabannister
  • 3,796
  • 3
  • 16
  • 25
1
vote
2 answers

Objective C - OS X - Issue adding NSShadow to NSImageView

I am trying to add a shadow to a NSImageView on an MAC application. I created a custom NSImageView class "ShadowView.h" and modified the drawRect: like so: - (void)drawRect:(NSRect)dirtyRect { [super drawRect:dirtyRect]; NSShadow *shadow =…
1
2