Dimming NSWindow and layer NSView on top - objective-c

Is there any way I could dim my NSWindow (basically putting a black transparent layer over top of it that you cannot click through) and then layer a custom NSView on top?

You could create an additional NSView which contains your custom NSView. This new NSView would simply draw the black transparent layer in its drawRect and capture all events to avoid them being passed through to the window.

A more compartmentalized way would be to make a borderless window containing the black view and the custom NSView, and make that a child window of the window you want to “dim”. Then use NSViewAnimation to fade the window in and out.
You will, of course, need to handle keeping their sizes matched if the “dimmed” window is resizable.

You could just set the background color of your NSWindow the black and change the opacity to your liking.

Related

Adding a UIView as a subview to UIImageView

I am working on creating a color picker for "iOS". I am using this project, since it does what i want: "This"
I want to create a moveable circle (UIView) on top of the palette (UIImageView).
What I want to do is, while users move the circle, take the touch point and call the method getPixelColorAtLocation(); and change the background color of the circle to the color on current point. (Seen on most of the color palette/wheels)
The method getPixelColorAtLocation() is available on a child view. I created a circle with UIView on parent view, the problem is I cant call to getPixelColorAtLocation() from parent view.
My question is, Is there anyway to add a UIView as a subView to UIImageView. If I cant, what choices do I have to achieve what I want?
Yes you can do this.
[myImageView addSubview:sampleView];
An image view is just a subclass of UIView, so you can add subviews to it however you'd like. If there's a reason why you can't do so, then you can always make it a subview of the image view's superview, move it to the front, and then use convertPoint:toView: to convert to the image view's coordinate system, then get the pixel color.

Drawing a transparent NSView in NSWindow with black background

I have a NSView inside a NSWindow and the background of NSWindow is set to black (with alpha of 0.7). Is there anyway to have the NSView showing what's underneath the NSWindow? In other words, how do I make the part where NSWindow and NSView overlap to have clear background?
Thanks!
You can try the setOpaque method
If I understand properly, it seems like you're trying to have a window with hole in it. You can take a look at apple's sample code Round Transparent Window. It shows how to add transparent areas to an NSWindow.

Borderless NSWindow with rounded corners

I am creating a custom NSWindow with no title bar and am using NSBorderlessWindowMask to make it completely borderless. The problem I have with this however is that the window has sharp edges. As well as this there is no resize control.
How would I give a borderless window rounded corners?
This is not a duplicate of this
question as that question was more
about removing the title bar and it
currently holds no answers.
You can make the window totally transparent and handle drawing everything yourself. The sample I have is for an OpenGL view, but it should work for a Quartz view or Cocoa view as well.
Add the following to the initializer of your NSWindow subclass where you create the new window using the NSBorderlessWindowMask constant.
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
You will probably have to draw the resize control yourself. The sample I took this from is a full screen window so resizing isn't necessary.
Good Luck.
The easiest way to get a window with rounded corners is to place a NSBox into the window as these boxes have customizable rounded corners and customizable borders. If you then set the window to non-opaque and the background color to transparent ("clear color"), you have a NSWindow with rounded corners that draws a normal window shadow (even on older systems where such a window would otherwise not have a shadow). Most of it can be done in Interface Builder. See here for details.
Only titled windows get the rounded corners. So the only thing you have to do is this:
window.styleMask = [.titled]
window.titleVisibility = .hidden
window.titlebarAppearsTransparent = true
This should be the minimal configuration for a rounded window without a title bar.

setBackgroundColor covers element

I have an NSWindow, and I'm using this code to add a bottom-metal-bar at the bottom.
[MyWindow setContentBorderThickness:40.0 forEdge:NSMinYEdge];
That works fine. But, once I use this:
[MyWindow setBackgroundColor: [NSColor redColor]];
The red covers the bar at the bottom. The bar shows correctly without the background color.
Yes, it would appear that changing the background-color of an NSWindow negates its bottom border. In order to achieve both effects, you can do one of two things:
In Interface Builder, move all your interface elements to a subclass of NSView that draws its background and add the view to your window.
Create an NSView that emulates the bottom border of your window and set the window's background color.
Personally, I would go for the first option, because it requires less work (trying to emulate a bottom border will be difficult, even with NSGradient) , but both are a possibility.

Custom NSWindow drawing

I want to draw an NSWindow that looks similar to this:
http://vibealicious.com/site/apps/notify/screenshots/mainUIFull.png
In that it has a typical NSWindow appearance with the bottom bar and such, but instead of a title bar at the top, I want to draw a little arrow.
Is there a simple way to do this? Do I have to draw the entire window by hand (bottom bar and all) ? Or can I slightly modify the existing NSWindow layout to just draw that arrow at the top? Thanks
You could possibly fake the title bar by using a second child window that overlays the top section of the window and draws just the arrow. Otherwise, you'd need to draw the whole thing yourself.
Not sure what you mean by a simple way to do it, but it's not very hard to make your own window subclass and draw the window controls yourself. A child window would be a bit of overkill for this situation.
Have a look at the Round Transparent Window sample project.