Cocoa - Replicate mail button bar - objective-c

How do I replicate the appearance of the button bar in the Mail App? I'm pretty close, but I cannot seem to get the colors to work the way I want.
If I set the background color for the view containing the buttons, it won't look the same as the NSTableView above it when the window loses focus.
Here is my app with focus:
My app without focus:
Mail.app with focus:
Mail.app without focus:
So in short, I want the same behaviour as the mail button bar with or without focus. How would one do that?

After spending a lot of time on this and then after finally asks a question here, I manage to fix it.
What I did was adding a bottom bar in IB and then programmatically setting the same color on the bottom bar as the background color on the NSTableView.

Related

Sub views in HUD Panel

I am working on OSX 10.10
I am facing a strange problem of sub view colors getting inverted for HUD Panel.
For example the button when set to default button looks right in Xib file but when executed the look and feel of button is modified by the HUD panel.
I am having a HUD Panel in my Xib file as follows
But when executed the button looses its default button status. It looks as follows
How do I maintain the look and feel of the button after execution. User is not able to judge which action will be the default action due to this look and feel
Try
_defaultButton.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
Interface Builder follows a set of rules but these rules are not context-dependent. The context I'm talking about is "being displayed in a HUD Panel".
The rule applied in this case is "draw a blueish button in Interface Builder if the button is a default button" even if it's not always what happens (cf. what you're seeing in your second screenshot).
I don't know since which OS X version it's working like that, but now controls in HUD Panels are displayed with a different style (which does not have a special color for default button).
You can confirm this Interface Builder comportment by adding a simple NSTextField in your HUD Panel, it'll draw with a white background in Interface Builder but it will have a black background when running with a gray focus ring.
Interface Builder:
OS X 10.10:
I've never found a way to disable this special styling for controls in HUD Panel but several workarounds (the default button is still working correctly even if not having a special color).
The special styling only occurs when your HUD Panel have a title bar.
self.panel.styleMask = (NSHUDWindowMask | NSTitledWindowMask | NSUtilityWindowMask | NSNonactivatingPanelMask);
If you remove the title bar, it'll display without any special styling:
self.panel.styleMask = (NSHUDWindowMask | NSUtilityWindowMask | NSNonactivatingPanelMask);
At this point, you can implement and draw your own title bar in the panel and mimic the default one. I don't really like this approach because first it's a lot of work for a simple button and the custom styling of controls make them prettier and more easy to read in a HUD Panel.
Another solution was the 'VLC' way. They use HUD Panels but their controls don't have any special styling. They're using BGHUDAppKit which was released when Apple provided HUD Panel without any special controls to go with it. They use it to force the bluish style instead of the greyish one which are now used by default in HUD Panels.
I didn't really like this approach too, I didn't want to add a library for a simple button, library not updated since 2011.
What I end up doing was drawing a custom button (with a simple subclass) for default buttons in a HUD Panel. This solution is quick and allow you to choose the color you want for default button in a HUD Panel (blueish may not be the best for a HUD Panel, your call).

Disable background and change tint color for custom popup

In my project I created some custom popups. Just like for example the UIActionSheet I would like to create an overlay, disable other interactions and gray out the tintColor of the UITabBar buttons, UINavigationBar buttons and so on.
As for now I've managed to fix this by manually creating a background overlay, disable the interaction by adding this overlay over other views and change the tintcolor manually.
I've searched for an API method to automatically solve this problem, but without success.
Hoping to find some good suggestions here at SO.
Edit
The answer I was looking for is called tintAdjustmentMode:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instp/UIView/tintAdjustmentMode
Add a new view in your xib
set background color as a black color and set the opacity to 50%
Create your popup on this view.
Put this view in the main view.
Finally just hide & unhide this view according to your requirement.
In this you don't need to disable any other control.

How do you vertically centering an image on an NSButton

I'm build a Mac application in the style of the Lion Mail.app. As part of this I'm attempting to create a simular toolbar to the one in the Mail.app but I can't seem to get the image in my toolbar button centered vertically.
Looking at the Mail.app toolbar I see a nice series of buttons with centered icons:
but when I go interface builder I can't seem to recreate the same button. What I get is:
What I've tried doing is, in Interface Builder:
Create a new window
Add a NSToolbar to that window
Add an NSButton to the toolbar with Style - 'Push', Image - 'Envelope', Position - 'NSImageOnly', Scaling - 'Proportionally Down'
As you can see the icon is clearly not centered vertically on the button like those in the Mail.app toolbar.
Anybody have any ideas???
At the moment I'm using XCode 4.2 and laying out this button with Interface Builder. I'm trying to build the toolbar button by ONLY adding the image to the button and not painting the button for each item, ie drawing the border and icon.
Any help would be greatly appreciated as this has been driving me a little nuts.
Thanks in advance - AYAL
Turns out the answer to this problem was much simpler then I had expected. After a lot of teeth gnashing, hair pulling, and twiddling pixels I came across the solution.
Instead of using a 'Push' button I simply had to switch to a 'Round Textured' button. Once I did that any image I added to the button was nicely centered. Next I just had to manually scale my image to look right.
The recipe then for a Mail.app Toolbar is as follows:
Add a button to your Toolbar
Set the button style to 'Rounded Textured'
Set the image of the button
Set the position to 'NSImageOnly'
Set the button size to 40 x 25 as well as the min and max sizes of the ToolbarItem
The result is a toolbar that can look very simular to the Mail.app toolbar.
Thanks All - AYAL
One way to do it is to have your image actually be the button i.e. take up all of the button's canvas. You will have to use the button's setBordered: method so the button's border is not drawn.
you could make the button image in something like gimp or photoshop then use that as the background or image for the button.
i feel like your going to say "this is what im doing". and maybe you made the little mail icon but i mean for you to make the whole button, outline and everything, then use that for the button image. make sense?
like here, just use this as the background

adding an invisible button to the background in IB

I'm working with Xcode doing a Ipad app.
i simply want user to click anywhere on screen (not counting text fields) to perform some IBAction.I'm using an invisible button that covers my whole view.
Since I have some text fields in my view,i need to add this invisible button to the background of my user interface. I cant seem to find this option in the button attributes? any help?
Just set the button's type to custom.
Did you try setting the opacity of the button to zero?
I guess i got your point. You just want to put the UIButton(invisible) on the back of all the UITextField. The simple solution to this is open the Document Window in the IB. Now expand the view tree in the list view. Just drag your UIButton above the UITextFields and set the alpha value for the button in the property to be zero.
Hope this helps!!
iPad users don't "click". They "tap" or "touch".
In Interface Builder, I believe views are constructed with a z-index from top to bottom as they appear in the document window, so dragging your button so that it appears as the first subview of your main view should be a quick fix for this.
Have you considered other approaches? This doesn't sound like standard behaviour for an app and will probably cause havoc with anybody using Voice Over. What are you trying to accomplish?

Why and how do I change my buttons style, my the other compose button is fine?

I've changed my navigation bar style to black opaque but my done button remains blue, yet the compose button is fine / black.
Why is is happening and more importantanly how do I fix this ?
The buttons was added in IB and shows blue there, while the nav bar is black.
The best thing to do is to make sure you're using the UIBarButtonSystemItemDone system button item, unaltered. If you really want to change the appearance of your Done button, you will need to assign a custom view to the bar button item's customView property. Then you'll be able to control every aspect of its appearance.