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

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

Related

Full height layout with NSSplitViewController with a Toolbar

I am working on a text editor app that needs an inspector sidebar for special actions with the text. I am therefore using an NSSplitViewController to manage the overall layout. I want the sidebar to take advantage of macOS' new full-height sidebars. I already have an NSWindow with a fullSizeContentView style mask. And my corresponding NSSplitViewItem has the property allowsFullHeightLayout set to true.
Unfortunately, I am still getting this layout:
Additional information:
The Inspector sidebar is an NSHostingView with a SwiftUI View wrapped inside.
When using the accessibility inspector, I can see that the sidebar layout is expanded all the way up, but the NSToolbar seems to be ignoring it.
I need to keep both the title and toolbar
It is possible to let the toolbar know that there's a split view divider by using a special NSToolbarItem. By creating a custom identifier and rendering it as an NSTrackingSeparatorToolbarItem, I was able to extend the line all the way up.
To make the inspector view background extend to full height layout, I had to use window.titlebarAppearsTransparent = true.
This blogpost helped me to figure out everything: https://christiangiacomi.com/posts/setup-nstrackingseparatortoolbaritem-macos11/

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 Big Sur new toolbar button style

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

Swift - Image color resets when Alert is displayed

So in my iOS app I have a menu designed like this:
The Images are created with the following code:
cell.imageCell?.image = menuItems[indexPath.row].image
cell.imageCell.image = cell.imageCell.image?.withRenderingMode(.alwaysTemplate)
cell.imageCell.tintColor = MenuTableViewController.fontColor
cell.imageCell.backgroundColor = UIColor.clear
This code is placed in the tableview cellForRowAt function. Now all the different viewcontrollers(HomeViewController, InfoViewController etc...) have no access at all to the menu controller and thus are not able to change the color of the image and nowhere else am I changing the color of these images. Now when I press one of the tabs that don't use any Alerts or modal views like home or info, the images stay perfectly fine, however when I press on Weather or excursions which download a json file with URLSession dataTask and display an alert telling to please wait, the images turn grey like the following:
I'm not sure how this is even possible that one viewcontroller can change another viewcontrollers subviews.
Thanks in advance
-Jorge
Perhaps what you see is a dimmed presentation of your icons. Don't use image templates or set tintAdjustmentMode to normal to stop fading icons. Usually that happens if you display alert or modal controller.
It looks like its the default UITableViewCell click style.
Try to set the style to none,
as answered here: How can I disable the UITableView selection highlighting?
Swift:
cell.selectionStyle = UITableViewCellSelectionStyle.none

iPhone - Custom Tab Icons, Remove Highlight

I am creating a custom tab bar for my iPhone app and I need to change the images. I have changed the actual tab bar background, but I need to know how to add custom images for the icons and their respective "selected" icons. I also need to remove the square highlight that is default. Pretty much, it just needs to be my icons. Also wondering if the images can be coloured or not. I've looked a lot of this, but no one seems to have the solution.
Someone please help.
hide the inbuilt tabBar view
create your own custom UIView (or UIScrollView in case if you need more number of tabs) with the frame of inbuilt tabBar view and fill up, especially with array of UIButtons & then add your custom view as a subview of the TabBarController.
Play with the UIButton's background image (which is your tab icon image) and its addTarget:action:forControlEvents: in order to set the appropriate selectedIndex value of the TabBarController, i.e. set the selectedIndex according to the button's position in the custom view.
This is how I've implemented :)
No. You cannot customise the tab bar icons in the UITabBar.
They are designed to be used with an alpha masked image.
Someone discovered a way to hack the colours though here: Custom colors in UITabBar