Mac Application bottom bar add button - macos

I added a bottom bar on NSWindow in IB by select "Content Border-Large Bottom Border". And I add a custom Image button on the bottom bar, but when I press the button, the background of the button turns into white, why?
This is the effect when press down the button:

Change button's type to Momentary Change. You can change it in Attributes inspector:
Or change programatically:
[button setButtonType:NSMomentaryChangeButton];

Related

Hidden window title with accessory view

I want to have a window with a hidden title, as seen in Safari or Xcode, but using a titlebar accessory view instead of a toolbar (I want more control over arrangement and content than a toolbar provides). Is this doable?
I haven't quite been able to make it work. If I set my window's titleVisibility to hidden, and my accessory view's layoutAttribute is bottom, then the title area is empty except for the standard close/minimize/zoom buttons, and my accessory view appears below that.
If I change the layoutAttribute to right, then my accessory view appears to the right of the standard buttons where I want it, but the bottom is cut off because the title bar isn't tall enough, and the view also doesn't resize horizontally with the window.
Is there a way to make this work? Or do I have to use a toolbar?
Update: I used Xcode's visual debugger to examine Xcode's own title bar, and found that it is using a toolbar. The debugger refuses to attach to Safari, so I'm left wondering how it does the new tab button. I imagine that button is a right-pinned accessory view, and the rest is a normal toolbar. Safari's toolbar is still customizable, so that seems most likely.
I decided to go ahead and use a toolbar, and it's working pretty well.
I took my NSTitleBarAccessoryController subclass and made it inherit from NSViewController instead.
I created a non-customizable toolbar for my window, with a single "Image Toolbar Item" in both the allowed and default sets.
The toolbar item has a height of 32 and a max width of 10000 so it can stretch to fill the title bar.
In my toolbar delegate, in toolbarWillAddItem:, I instantiate the view controller from the nib and put its view into the item.
A text label that is effectively the new window title has its value bound to the window's title.
To match the spacing in Xcode's title bar, use a left and right margin of 1 pixel (zero will cut off the edges) and a top margin of 5.
window.titleVisibility = .hidden moves the toolbar into the title area.

Popover not attached to anchor

I'd like to show a popover with it's arrow to a button that is part of my view (e.g. button is on my main view). I do this in Interface Builder storyboard editor (ctrl drag from button to popup contents view). Popup shows but not attached to the button. What I found for the buttons on the toolbar popover shows attached to the button as expected. Anchor property of the segue is set to this button. Xcode Version 7.0.1 (7A1001).
Edit: images of what I do:
1) Storyboard. First I ctrl drag from toolbar button to first controller, then ctrl drag to second controller from second button.
2) Correctly attached popover
3) Popover not attaches to in-view button.
You are right. Following method shows that the sending view is nil and by default contentview of window is used for popover.
So to fix just check if the positioningView is nil. if yes, set it to be button (create outlet for it).
Add following method to your viewController
- (void)presentViewController:(NSViewController *)viewController asPopoverRelativeToRect:(NSRect)positioningRect ofView:(NSView *)positioningView preferredEdge:(NSRectEdge)preferredEdge behavior:(NSPopoverBehavior)behavior
{
//do custom implementation (workaround)
[super presentViewController:viewController asPopoverRelativeToRect:positioningRect ofView:positioningView preferredEdge:preferredEdge behavior:behavior];
}

Text in disabled round textured NSButton is not greyed out

I have an NSButton created in Interface Builder with the style "Round Textured". When the button is disabled, the text colour does not go grey as you would expect. Oddly enough when the button contains an image instead of text, the image does go grey, as seen in the below screenshot (top buttons are enabled, bottom buttons are disabled).
How can I get the text to go grey when the button is disabled?
Update: So it gets weirder: the view containing the button is shown in a popover and every second time the view is shown the button is greyed out.
It seems, at least in Yosemite, as long as you set button.wantsLayer = YES on the button view, that it then works. Go figure.

cocoa: how to make a image button like app store

Instead of push button, I want to implement a image button like app store, as you can see in the image bellow:
after I click Featured image button, the image turns blue.
My question is:
how to make a image button?
how turn the color after click it?
I can add a image into a square button, but it doesn't like the app store button.
Create another image - blue image and just change it using -setImage in button's action (example at the bottom). Use Gradient Button's style (It can be changed in Attributes Inspector -> Style) then You can change button's size easily. Don't forget to choose button's type to Momentary Change (it will remove white background when pushing button). Also remove border, unchecking Attributes Inspector -> Visual -> bordered checkbox. Add alternate Image (Your blue image).
Example: (when button is clicked it will be changed to blue image)
-(IBAction)buttonAction:(id)sender {
[buttonOutlet setImage:[NSImage imageNamed:#"yourBlueImageFromResources"]];
}
Note: don't forget to IBOutlet button to buttonOutlet.

How to create a window looks like Tweetie Mac OS X app new post window

I have some questions about this window:
What type this window is (I've found that only "Textured Window" has rounded bottom corners)?
Why it doesn't have a title? Could I add it?
How to add a label to the title (word counter).
How to add a bottom bar?
This is just a plain old NSWindow. It's not textured. You can set a title with setTitle: in code or the Title field in the IB inspector. Tweetie's window doesn't have a title because the developer chose not to give it one.
The bottom bar is created by setting the content border on the window. Look under the Size tab in the IB inspector. (Uncheck "Autosize" and put in a value.) You can also pick "Large bottom border" from the popup menu in that tab and have IB set it up for you.
You can add a label in Interface Builder. Just type "label" into the Library filter search box and it will come up.

Resources