Window title bar appears transparent issue (Not really transparent) - swift

I am trying to make my app have more 'flat' feel so I think it is a good idea to hide the title bar.
However, in reality titlebarAppearsTransparent seems only remove the title bar shadow but not make the title bar truly transparent.
Before using any code to modify the title bar,
After adding the following code (starting have a better feel),
self.window?.titlebarAppearsTransparent = true
Setting the background color to white,
self.window?.backgroundColor = NSColor.whiteColor()
self.window?.titlebarAppearsTransparent = true
This is certainly not what I want. I thought I just turned the title bar transparent to true. What is going on here?
Any hint or comment is appreciated and thanks for your time viewing this question.

Try add:
self.window?.styleMask |= NSFullSizeContentViewWindowMask
When set, the content view consumes the full size of the window; it
can be combined with other window style masks, but is only respected
for windows with a title bar. Using this mask opts in to layer
backing. Use the contentLayoutRect or contentLayoutGuide to lay out
views underneath the title bar-toolbar area
If you don't want to keep the title bar at all, you can also added:
self.window?.titleVisibility = NSWindowTitleVisibility.Hidden;
The window hides the title and moves the toolbar up into the area
previously occupied by the title.
You might also wanted to add this in order to move the window by dragging its content view:
self.window?.movableByWindowBackground = YES
A Boolean value that indicates whether the window is movable by
clicking and dragging anywhere in its background. The value of this
property is YES when the window is movable by clicking and dragging
anywhere in its background; otherwise, NO.

Related

How to make transparent navigate bar with Table View Cell

I faced with the Table View Cells issue. If I choose default View Controller settings, cells are located under transparent navigation Bar. This is unacceptable because bars items overlap the cell.
navigation bar overload the tableView
If I changing Extend Edges setting at the tab on the right side, specifically "Under Top Bars", cells as expected are located under bar, but in this case NavigateBar is black.
navigation Bar is black
As you see I tried to fix that issue with the Simulated Metrics, but nothing is chanced. Also self.navigationController?.navigationBar.isTranslucent = true and self.navigationController?.view.backgroundColor = .clear in viewDidLoad method did't give any result. I able to color navigation Bar, but i need it transparent. Any ideas?
I guess you haven't set a background color to the ViewController's view. That's why it's appearing black.
Try adding the background color you want and it should work as expected.

NSTabView Background Color

I have a window controller with blue background color
The background color of all children view controllers work fine with blue background just like their parent window controller, except NSTabView of NSTabViewController, which draws with the original gray background
I am not sure why it does not inherit the background color, or why it is not transparent
Anyway, to solve the issue, I tried the following
(1)
I tried editing the CLayer background
tabView.layer?.backgroundColor = NSColor.blue.cgColor
I tried putting that code everywhere, and the only time it worked is when I accessed the CLayer from a tabViewItem inside its viewWillAppear function or viewDidAppear or viewWillLayout, but the problem is that this code does not work until I select another tab... i.e. when the tabViewController is shown at the beginning, the initial view background color is grey, and does not change to blue until I select another tab!
From my understanding, the tabView is drawn after its child viewDidAppear, that's why it overcame the blue color order, and when another tab is selected, the viewDidAppear function is called again changing the color to blue (since the tabView` is already drawn)
(2)
I tried to change drawsBackground value to false
when the tabviewcontroller is shown, the background is just like what its windows is, blue, but as soon as I choose another tab, black residue are left from the previous tabviewitem controls
any idea how to solve this problem is much appreciated!
I solved this by adding a Custom Box to the initial tab with the required background color, and resized it to the size of the view
In the rest of tab views, I added this line to viewWillAppear function
tabView.layer?.backgroundColor = NSColor.blue.cgColor
The custom box feels like a hack but is the only way around I could come up with
An alternative solution is to place a custom NSBox behind the NSTabView with the correct size and background color. No further code needed, as long as all tabs feature a transparent background.

How to add a titlebar to a popover

I'm trying to replicate the appearance of the (no longer functional) Degrees app, but I can't figure out the components used to make the title bar (highlighted here in red).
I've managed to get my app running as a menu bar agent, and I've wired up a popover to display a window view on click. But it's not quite right: my window's title bar disappears when in the popover, and the bar used in the Degrees app is wider than the one provided by the stock window control.
How might I mimic the appearance here? it just an ImageView?
Popover's don't show window title bar's as you've discovered.
Just add an NSView at the top of your window view and add a label for the title and a button for the "Done" button to create your top bar with desired height. Then add a horizontal line to the bottom of this title view and programmatically set the background color of its layer to whatever you desire. Offset all your other views by that bar height.
Basically:
[Window]
[View]
[View (Title Parent)]
[NSTextField]
[NSButton]
[Horizontal Line]
[Other Views]
For getting the gray background, in your NSWindowController windowDidLoad,
self.titleParentView.wantsLayer = YES
self.titleParentView.layer.backgroundColor = [NSColor grayColor].CGColor;
where titleParentView is an IBOutlet connected to the view you created above in the xib/storyboard

Swift / Set a white background on back button on navigation bar

After a lot of research, i have to resign...
I'm working on Xcode7, and swift.
I have a transparent navigation bar, so when i'm scrolling on the viewcontroller (a map), i would like the back button be more visible, so with a white opaque background.
Any idea to perform that ?
Maybe, just to insert an image as back button.
In your main.storyboard file, click anywhere in the storyboard that is not a viewcontroller, so in the white space. Then in the file inspector, there is property Global Tint that will change the back bar text color. I've looked around for other ways to change it, such as changing the back buttons text color programmatically, and none seem to work. Hope that helps.

Why tab bar upper half's color is lighter than bottom half

I create a navigation tab bar on the bottom of iphone and use dark gray color as tint color. Every things is good except the upper half's color is a bit lighter than bottom half. I also didn't fix it by programmatically set background color and tint color in viewDidLoad. This problem happen both of simulator and my iphone 5
This effect was added by the system in the default way, not a bug or problem.
You can custom UITabBar in this way:
tabController.tabBar.backgroundImage = [UIImage imageNamed: #"TabBarBG"];
Not only reset the background color or tint color.Have a try.
That's the visual effect "gradient" added automatically by system. You can write a custom tab bar yourself to change the effect.
This is default behavior of tab bar.
However you may change this by setting bakgroundimage for tab bar.