OS X Use NSImageView for NSWindow background - macos

I am trying to use an NSImageView as the background for an NSWindow I have it setup and it shows the image just fine I am using the full size content view to have the image take up the whole window. The problem I am having is the title bar with the buttons is being placed over the image and it is a transparent white color.
Is there a way I can make the title bar for a window transparent?

I am dumb the answer I was looking for is to call
[self setTitlebarAppearsTransparent:YES];
Reading documentation works!

Related

How to temporarily disable UIView background image from responding to mouse clicks in Interface Builder?

I have a UIView background image that I want to use for my view.
Now, on top of this image, I want to have buttons and position them relative to what I see in the image.
The problem is, these buttons were already added to the view before the background image was added. So now when I put the background image, entire view is background image and I am unable to access the buttons underneath it in Xcode.
Is there a way to tell Xcode that I am not interested in the UIView but actually the buttons that appear underneath it?
Check - (void)sendSubviewToBack:(UIView *)view in UIView
Would be something like
[self.view sendSubviewToBack:backgroundImageView];

Give NSWindow a background image

Ok, so I've created an image in Photoshop that will align with the buttons on my app, and now I'd like to make it the background image of my window so that the characters on the image will correspond to the keys on my app (a small calculator demo app I've been working on)
Basically, instead of giving buttons Text like 1,2,3,4, etc. I've made a 3x3 map with numbers of a different font just because it will look pretty
What I'm having difficulty with now is that I can't seem to make the image the background of my window.
I created an NSImageView and I dragged the image file onto it, so I can see it now, but I can't make it the background.
Do I need to subclass the NSImageView or is there some simple method?
I'm using XCode 4, btw
Thanks!
I think you should be able to do something like:
[window setBackgroundColor:[NSColor colorWithPatternImage:[NSImage imageNamed:#"myImage.png"]]];
This is something that a layer-backed window would be good at:
[[window contentView] setWantsLayer:YES];
[[window contentView] layer].contents = myImage;
I think you stand a better chance of getting this to resize sensibly (assuming you need to) than with a pattern color.
Just to give you more options -- you should be able to [window setContentView:myImageView]. In the .xib file you'd want to add your buttons etc. as subviews of the image view.
I don't necessarily recommend this approach, but it's something to think about.

Animation in NSStatusItem

I'm writing a status bar application for OS X and I want to use an animated 'loading' gif as the icon when waiting to download a file.
Passing the gif in an NSImage to the setImage: method of the NSStatusItem set the status bar icon as the first frame of the image, but was not animated. I put the NSImage in an NSImageView and passed that to the setView: method but then the status item didn't show up at all.
How can I do this?
you might wanna use the NSProgressIndicator of spinner style and use setView to it. I'm having the same problem as you.

Changing color of the NSWindow titlebar

I am developing a desktop application in which I want to change the color of the title bar of an NSWindow. How exactly can I do this?
NSWindow's content view has a superview, which is an instance of NSThemeFrame. That class is responsible for drawing the title text, the window/toolbar background texture, and it contains subviews for everything else (close button, full screen button, NSDocument icon, etc).
You can use the Objective-C runtime to replace NSThemeFrame's drawRect: method with your own method, which will call the parent implementation and then perform custom drawing on top of it.
There is also a private method to find the rect the title is drawn in, and public methods on NSFont to find it's font and font size.
What I did is set the window background colour to be a solid colour (black) instead of a gradient/texture, then set it to be a "textured" window (which causes the background colour to actually be rendered, otherwise it would not happen), then I draw a black square over the title bar in the area where I know the title has already been drawn, then draw my own title in it's place, with light grey instead of dark grey.
Source code is here: https://github.com/abhibeckert/Dux/blob/master/Dux/DuxProjectWindow.m (note: it only does a custom title text colour if DUX_DARK_MODE == 1)
Doing this will probably get your app blocked from the Mac App Store, but it is fairly reliable. Just make sure you test it with every new major version of OS X.
To change the color of the window's toolbar:
Set window style Textured in Attribute inspector.
In code: [window setBackgroundColor: MyCustomColor];
This uses private methods, but works:
NSEnumerator *viewEnum = [[[[[[window contentView] superview] titlebarViewController] view] subviews] objectEnumerator];
NSView *viewObject;
while(viewObject = (NSView *)[viewEnum nextObject]) {
if([viewObject className] == #"NSTextField") [viewObject setTextColor: .. your color .. ];
}

Change color of title bar in cocoa

This must have been asked before, but after Googling I still can't find the answer.
How do you change the color of the title bar (The bar that you can click and drag around with the close, minimize and maximize buttons) to a different color than the default gray in Cocoa?
If you set the background color of a "textured" window (a distinction that isn't really all that visible in Snow Leopard) that color will be applied to the titlebar as well. This is what Firefox does.
I would recommend though not having a real titlebar (i.e. setting your window to have no titlebar) and using +[NSWindow standardWindowButton:forStyleMask:] and putting your own buttons in the "titlebar". This allows you more control and is way way less hacky.
If it's a panel, you can change it to black by instantiating it as a HUD window.
Otherwise, you can't. Ever notice how there aren't any Aqua windows with different-colored title bars roaming around in other apps? This is why.
The only other way to change the appearance of the title bar (without relying on private implementation details such as the existence of a frame view) is to make the window borderless and create its title bar and window buttons from the ground up.
If you go with Colin's approach of making the window textured in interface builder (check box in the attributes of the window), here's the line to change the background color of the window you'd put in this function of the appDelegate.m file
//In this function --->
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
//type this
[_window setBackgroundColor: NSColor.whiteColor];
If you don't mind private API, you could subclass NSThemeFrame.
Setting title bar appears as transparent
self.window.titlebarAppearsTransparent = YES;
And setting window background color as you wish

Resources