How to change the background behind the stack of sheets in SwiftUI? - swiftui

How can I change the background here (black) to another color? I was playing around with an app called Honk, and they've set different backgrounds in some of their sections. I saw something on SO that said it could be done with window.backgroundColor = .magenta but I have no idea where to put that. I assumed it would either be inside the init() or as a property on the highest-level view of my app ie NavigationView, but no luck so far.
Here's a screenshot from Honk for reference:
And another:

Related

Swiftui fixed background across views in a Navigation Hierarchy

I'm building an app in Swiftui and want to have a fixed image background that is consistent among all screens and is also enclosed in a Navigation Stack Hierarchy, meaning I can go on to different screens and swipe from left-to-right to go back, etc while still have the fixed image background.
I have tried various solutions but havent been able to achieve this. Closest thing I came up with was to create a full screen overlay but that doesnt solve the problem. Any and all help is appreciated :)

SwiftUI: Status bar color for specific view

I have a specific view in my application where I need the status bar to be white (dark mode).
I've tried setting the .preferredColorScheme(.dark) but as the documentation mentions, that affects all the views in my window which is not what I'm looking for.
I've taken a look at this but it seems to be done using SceneDelgate which I am not making use of.
Is there any workaround to this?
For iOS 16, you can set .toolbarColorScheme for a specific View. Unfortunately, this is not supported on older iOS Versions. As a workaround that does not involve SceneDelegate, you could manipulate UIToolBar.appearance() directly with a new tint color. This has nothing to do with the preferred color scheme (e.g., light or dark mode), but could have the same effect.

how to change apache superset's chart's background color?

Per How to Change Apache Superset Template from the Superset User Interface? , I was able to change the CSS template for Superset dashboard. But the charts inside the dashboard are not affected. e.g. most of the charts have white colored background(e.g. Piechart) and some people dislike it. How to change the chart background color? I mean change it for all charts or for one chart.
Disclaimer: This should work, but is a bit hacky and could have long-term support implications:
I've been fiddling with a "dark mode" dashboard just to kick the tires on this. Here's a screenshot just for fun:
So... what did I do?
Click "Edit Dashboard" in the top right of your screenshot
When in edit mode, the top right menu has an option to "Edit CSS"
Use your browser's inspector to hack away! That said, here are a couple of key ingredients:
.dashboard-component{ background: whatever} - sets the main background of each viz card, but you'll still see many components still have white backgrounds within these wrappers.
.slice_container svg{
background-color: transparent !important;
} - this overrides the white background of the components I ran into (including Pie charts!).
If viz components use SVG you can get pretty clever with inspecting/overriding various bits. A couple of gotchas with the above:
If a viz component contains multiple SVG elements, this may have side effects.
If a viz uses canvas instead of svg you will run into more trouble
In the worst case scenario, you may need to check out the superset-ui-plugins repo and make tweaks. This dev process isn't super straightforward, but some of us are working to improve that.
Easiest solution for me is using dark reader extension.

UITabBar is changing color on screen change

I am workingwith xcode9 and Swift 4. In my application I am using a tab bar. Which looks like this normally.
But on few screens as soon as i land it changes the background color and shows something like this. Can someone point out why this happening??
Thanks in advance.

QApplication::processEvents not working in Windows

I am working on a project that presents live data acquired in real-time using the QCustomPlot plug-in for Qt. The display has a black background color, and the multiple channels of data are colored differently. When taking a screenshot, we would like to make it printer-friendly, so the background is white and all data is black. I am thinking of a solution like this:
Change all colors the way I want by manipulating the pointers for the graphical objects
Grab the screenshot using QWidget::grab() to get a QPixmap
Change all the colors back to normal
This did not work at first, because the system could not change the colors in time for the screenshot to be taken. So I used a QApplication::processEvents(), and it all worked on my Mac.
However, it does not work on a Windows 7 (which is required). Any ideas what to do?
Code:
QSting fileLocation = "...";
toggleColors(false); //function to toggle the colors
QApplication::processEvents();
QPixmap shot = grab();
toggleColors(true);
shot.save(fileLocation, "png");
Again. It works on Mac, but not Windows.
Update 1. Content of toggleColors include:
if(enable)
ui->plot->setBackground(QBrush(Qt::black));
else
ui->plot->setBackground(QBrush(Qt::white));
ui->plot->repaint();
I also tried with ui->plot->update() instead.
I am not sure what is the problem on Windows specifically, but I recommend you calling QWidget::update() on the given widget. That forces the next update to re-render itself.
On the other hand, I'm not sure why toggleColors() didn't somehow cause that to happen.
Also, ensure that QWidget::setUpdatesEnabled(bool) wasn't set to "false."
It appears the problem lies with QCustomPlot. It was solved by performing a ui->plot->replot() which is specific to QCustomPlot and not QWidget.