NSTabView Background Color - swift

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.

Related

NSSegmentedControl - Odd appearance when placed in blur view

I have a macOS app with a simple popover view and a NSSegmentedControl placed within it. Everything works fine, apart from the odd appearance of the segmented control. It has this weird square background when placed in the pop over view.
Is there any way to get rid of this?
Apparently, labels inside NSSegmentedControl ignore vibrancy effect.
To fix it, put NSSegmentedControl inside NSVisualEffectView with material set to popover.

Window title bar appears transparent issue (Not really transparent)

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.

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.

UISearchBar background fading in and out when segue push animates

I created two views that has its transition controlled by a navigation view controller. I have a UIView which contain a UISearchBar. The UIView is then set as the navigation bar's titleView in the first view.
Now, the problem is, whenever I go from the first view to the second view, I can see a light background behind the UISearchBar fading in and out.
I have did a bit of troubleshooting of my own and found that the background belongs to the UISearchBar and not the UIView that contains it. I have also tried many codes to make the UISearchBar background transparent, but none of the codes actually makes it transparent.
Edit: I did a bit more fiddling and found that the colour fading in and out is the colour from the style/tint of the UISearchBar. So if I change the tint to black, it'll darken instead. The only way I see I can fix this is to turn the background of the UISearchBar's alpha to 0, but I can't find any code that can change the alpha of a UISearchBar in a UINavigationBar.
Edit: I really can't find any code to turn the background tint of the UISearchBar to be alpha 0. Does anyone have a workaround or an alternative solution to this?
I realised that the bar is actually the scope bar's background. I'm not sure why it still showed up even though I disabled it. My solution was to set the background image as a transparent image.
[self.searchBar setScopeBarBackgroundImage:[UIImage imageNamed:#"transpixel.png"]];

Making part of the view transparent/overlay while the rest isn't

I'd like to show an overlay view similar to what you see when you perform a 'Search in Contacts app where the SearchBar is visible under the toolbar while the gray overlay covers up all of the content below.
For my view, I'd like to have an UITextField and button shown visible while the rest of screen is gray with the rest of the existing contents as grayed-over and no SearchBar.
Things I tried:
I can have one view that encases
both UITextField and button with the
view's alpha level set to 0.5. But
this yields grayed appearance for
everything, including the
UITextField and button, which is not
what I'm trying to achieve.
I then tried two child views within
a parent UIView, with one subview
containing the controls while the
other one is blank. Set the parent
UIView to have 0.5 alpha -> this is
not right either.
Continuing with two child views
within a parent UIView, set the
parent view to have alpha of 1.0 and
then the the blank-view to have an
alpha level of 0.5, it's still not
right.
So what's a good way to achieve this?
Option 3 is the way to do it but make sure you're adding them in the right order i.e. transparent view added as first subView to parent view then the text field. This way the text field is on top.
Also, don't forget to set the backgroundColor attribute of the parent view to [UIColor clearColor].
I would've thought #3 would be the correct way to do it. Are you sure you have the parent and the overlay views's opaque property set to NO?