macOS Big Sur new toolbar button style - swift

When I create an App with SwiftUI App Lifecycle the toolbar buttons match with the new Big Sur toolbar button style (with onHover effect style). But if I choose the conventional AppDelegate Lifecycle and customize the toolbar via Storyboards then I get this button style without onHover effect:
The button appears with a rectangle as background. Does anyone know how could I achieve the new style?

I've got this effect after I set NSButton.showsBorderOnlyWhileMouseInside property.
button.setButtonType(.momentaryPushIn)
button.isBordered = true
button.showsBorderOnlyWhileMouseInside = true

toolbarItem.isBordered = true
isBordered property will give you that hover effect.

I've just had this problem myself and found the following NSButton settings to work.
Button style = Textured Rounded
Type = Momentary Light

Related

NSWindow - hiding titlebar while keeping control buttons with Cocoa/AppKit (NOT SwiftUI)

I'm building a macOS (OSX) application with XCode and I'm trying to get rid of the titlebar (maybe it's called toolbar?) in top of the window while still keeping the 3 control buttons (close, minimize and full screen).
So far I'm only able to hide this bar while keeping the buttons, but it looks like the bar is still there somehow. My NSTableViews recognize this as the bar and create some sort of transparent safe area before the rows and headers.
Here is what I got so far:
And here is what I want:
Notice that application is using UIKit and storyboards - NOT SwiftUI. The green area to the left is a sidebar of a NSSplitView. Just so you understand the structure.
I have these attributes set for the NSWindow at the moment:
Deployment target: macOS 12
XCode: 13.1
Swift: 5
Thanks!
You can accomplish what you are looking for by setting the window's title bar to transparent, hide its title text and set its appearance to Full Size Content View.
Sample Project
If you would like to have your table view ignore the top inset you need to set its enclosing scroll view automaticallyAdjustsContentInsets property to false
scrollView.automaticallyAdjustsContentInsets = false

MacOS: Any way to hide window title and not toolbar item labels?

I'm trying to make an app very similar to Apple's Mac OS App Store where the window's title is not visible but it has a toolbar with icons and labels.
The problem is that when I set the window's title visibility to hidden in my Window Controller, it also hides the toolbarItem labels.
window?.titleVisibility = .hidden
I tried explicitly setting the toolbar to show both icons and labels, but it seems to be ignoring this.
toolbar.displayMode = .iconAndLabel
Here is a screenshot of my app both with and without setting the title visibility:
You can do instead of
self.window?.titleVisibility = .hidden
the following
self.window.title = "" // no title but the labels for toolbar icons are there
you'd need to start with a 'raw'/borderless nswindow and you'd have to draw it all yourself. there is a nice INAppStoreWindow (or it was nice 4 yrs ago ;)) on github that does all to mimic the appstor look and feel

Avoiding making a NSButton transparent / see-through when isEnabled is false (disabled)

A regular NSButton seems to be transparent if it’s disabled.
Image shows a Button with style 'push'
However, I want to disable the Button without the transparency.
I’ve tried to programmatically set the alphaValue to 1.0 but it seems that the NSButtons cell (controlView) as well as all other subviews are already at an alphaValue of 1.0.
Also, there’s nothing like userInteractionEnabled or adjustsImageWhenDisabled (both recommended here) I could use like in iOS.
How can I disable a NSButton without the standard transparency?
EDIT: Also a 'textured push' button appears to be transparent:
If you don't need the title, and will provide your own button image, you can use setImageDimsWhenDisabled to disable transparency in NSButtonCell's image when it is disabled. Here is the code:
[buttonCell setImageDimsWhenDisabled:NO];
NSButtonCell is the subview of NSButton. But as I said, the title will still be "dimmed" a little bit, and also its background. But since image if on top of the background, you won't see the transparent background.
Another way (avoid subclass NSButton) is to have your own state tracking variable for button. When the state is disabled, dismiss any click event. Sample framework of code is like this:
- (IBAction)clickOnButton {
static BOOL isEnabled = YES;
if (isEnabled) {
// Handle click event here...
}
isEnabled = !isEnabled;
}
This may show the highlight when clicked. You can disable highlight also. But this is not a good idea if you have many buttons. If you have many buttons, subclass NSButton is the best choice.

iOS custom navigationBar button item

I would like to set navBar buttons like safari as following image shows. However I can only set a custom image for toolbar button but square button container remains although I set plain style. How to reach it? Thank you
Plain is only for tool bars not nav bars, that's the only way you can achieve no border. You must use a custom UIButton on your navbar to achieve the same results.
If you need an icon somewhat like that, you can check on Default Icon
Use UIBarButtonItem method for creating bar button
- (id)initWithCustomView:(UIView *)customView;
and create custom view with UIButton of type UIButtonTypeCustom

UIBarButtonItem Done State Without Border

I have a UIToolbar where all the buttons have a style of UIBarButtonItemStylePlain. One of these buttons toggles a setting in my app and I would like to have some type of Selected state when that feature is enabled.
Since I am not using bordered buttons, setting the style to UIBarButtonItemStyleDone would not work because the button would not match. Is there an easy way to change to color of the icon on the button?
For a sample, look at the location button in the Maps app on the iPad. It does exactly what I am looking for.
Sure thing. You can set the background image with initWithImage:style:target:action: or supply a custom view with initWithCustomView: