我将while
使用NavigationBar
backgroundColor,将dark
使用statusBar
textColor,但是当用户将主题iOS更改为深色时,我的statusBar
中的textColor更改为while
和while
的{{1}} backgroundColor上,我什么都看不到。如何为我的应用禁用此更改?
答案 0 :(得分:14)
int [][] myMatrix = new int[n+1][n+1];
是UINavigationController
(谁知道?)的子类!
因此,当展示嵌入在导航控制器中的视图控制器时,并不是真正展示嵌入的视图控制器;您正在展示导航控制器! UIViewController
作为UINavigationController
的子类,继承了UIViewController
和preferredStatusBarStyle
,您可以根据需要设置它们。
以下任何一种方法都可以使用:
childForStatusBarStyle
中,添加以下属性:
info.plist
(又称“用户界面样式”) 在UIUserInterfaceStyle
内覆盖preferredStatusBarStyle
UINavigationController
(doc)-视图控制器的首选状态栏样式子类或扩展preferredStatusBarStyle
UINavigationController
OR
class MyNavigationController: UINavigationController {
override var preferredStatusBarStyle: UIStatusBarStyle {
.lightContent
}
}
在extension UINavigationController {
open override var preferredStatusBarStyle: UIStatusBarStyle {
.lightContent
}
}
内覆盖childForStatusBarStyle
UINavigationController
(doc)-在系统需要视图控制器用于确定状态栏样式时调用“如果容器视图控制器从其子视图控制器之一派生其状态栏样式,请[重写此属性]并返回该子视图控制器。如果返回nil或不重写此方法,则状态栏样式为使用self。如果此方法的返回值发生变化,请调用setNeedsStatusBarAppearanceUpdate()方法。“
子类或扩展childForStatusBarStyle
UINavigationController
OR
class MyNavigationController: UINavigationController {
override var childForStatusBarStyle: UIViewController? {
topViewController
}
}
您可以返回上面想要的任何视图控制器。我推荐以下之一:
extension UINavigationController {
open override var childForStatusBarStyle: UIViewController? {
topViewController
}
}
(doc)-导航堆栈顶部的视图控制器topViewController
(共UINavigationController
个)({{3}})-与导航界面中当前可见视图关联的视图控制器(提示:这可以包括“已显示的视图控制器在导航控制器本身的顶部”) 注意:如果您决定继承visibleViewController
的子类,请记住通过IB中的身份检查器将该类应用于您的导航控制器。
P.S。我的代码使用Swift 5.1语法?
答案 1 :(得分:7)
如果您将应用程序UIViewControllerBasedStatusBarAppearance
中的info.plist
键设置为YES
,则可以在当前显示的视图控制器中覆盖状态栏样式:
override var preferredStatusBarStyle: UIStatusBarStyle {
if #available(iOS 13, *) {
return .darkContent
} else {
return .default
}
}
答案 2 :(得分:2)
您可以尝试使导航栏始终light
if #available(iOS 13.0, *) {
navigationController?.navigationBar.overrideUserInterfaceStyle = .light
}
答案 3 :(得分:0)
您可以将扩展名写入UIStatusBarStyle
:
extension UIStatusBarStyle {
static var black: UIStatusBarStyle {
if #available(iOS 13.0, *) {
return .darkContent
}
return .default
}
}
然后您可以轻松地在ViewControllers中使用
override var preferredStatusBarStyle: UIStatusBarStyle {
.black
}
答案 4 :(得分:0)
如果您使用的是UINavigationController
,请像这样在扩展名(或您自己的子类)中覆盖preferredStatusBarStyle
(只是覆盖您的preferredStatusBarStyle
视图控制器不起作用):
extension UINavigationController {
override open var preferredStatusBarStyle: UIStatusBarStyle {
guard #available(iOS 13, *) else {
return .default
}
return .darkContent
}
}
正如弗兰克所说,UIViewControllerBasedStatusBarAppearance
必须在您的YES
中设置为info.plist
答案 5 :(得分:0)
有两种方法可以解决此问题。在UINavigationController后代类中定义childViewControllerForStatusBarStyle函数:
@interface MyNavigationController : UINavigationController
...
@end
@implementation MyNavigationController
...
- (UIViewController *)childViewControllerForStatusBarStyle
{
return self.topViewController;
}
...
@end
在那之后,您需要为每个控制器添加功能preferredStatusBarStyle。
第二个选项是为所有控制器定义preferredStatusBarStyle函数。但是此函数不应位于根控制器中,而应位于UINavigationController的后代类中。
@interface MyNavigationController : UINavigationController
...
@end
@implementation MyNavigationController
...
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
...
@end
但是,即使在这种情况下,也必须为所有隐藏导航栏的控制器(如果有)定义函数preferredStatusBarStyle。
答案 6 :(得分:0)
我已经做了类似的事情。
我具有切换功能,可根据显示的View Controller切换状态栏样式
// here AlertsRequest.create(phone, true) mocking as null.
// But when actual call is made it creates a Object of AlertsRequest with phone as null & another parameter as true
// that's the reason mocking was creating for api.alerts("-1", null, null)
// here is it was api.alerts("-1", null, AlertsRequest(null, true))
api.alerts(id, userManager.getNonNullUserId(), AlertsRequest.create(phone, true))
这是最重要的部分
void getAlerts(AlertsRequest request) {
isPhoneLoadingData.setValue(true);
alertDisposable =
api.alerts(id,
userManager.getNonNullUserId(), request)
.doOnEvent((product, throwable) -> isPhoneLoadingData.postValue(false))
.compose(RxSingleSchedulers.DEFAULT.applySchedulers())
.subscribe(alertsData::setValue, errorData::setValue);
}
其中isDarkStyle表示导航栏背景颜色为深色或浅色。如果颜色较暗,则文本(内容)应为浅色;如果颜色较浅,则文本(内容)应为默认色,或从iOS 13开始为黑暗。
总结:pip install jupyterlab
独立于暗模式显示,这是应该做的。尽管C:\Users\HASAN>pip install jupyterlab
Collecting jupyterlab
Using cached https://files.pythonhosted.org/packages/2c/89/a4e048f198867f19d2a9f40d08c946d760ab06dd39d774940a20da47b5f9/jupyterlab-1.1.4-py2.py3-none-any.whl
Requirement already satisfied: jinja2>=2.10 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jupyterlab) (2.10.3)
Requirement already satisfied: tornado!=6.0.0,!=6.0.1,!=6.0.2 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jupyterlab) (6.0.3)
Requirement already satisfied: notebook>=4.3.1 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jupyterlab) (6.0.1)
Collecting jupyterlab-server~=1.0.0
Using cached https://files.pythonhosted.org/packages/78/98/5b87b9d38176bd98f23b58a8fb730e5124618d68571a011abbd38ad4a842/jupyterlab_server-1.0.6-py3-none-any.whl
Requirement already satisfied: MarkupSafe>=0.23 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jinja2>=2.10->jupyterlab) (1.1.1)
Requirement already satisfied: Send2Trash in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (1.5.0)
Requirement already satisfied: traitlets>=4.2.1 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (4.3.3)
Requirement already satisfied: pyzmq>=17 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (18.1.0)
Requirement already satisfied: jupyter-core>=4.4.0 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (4.6.0)
Requirement already satisfied: ipykernel in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (5.1.2)
Requirement already satisfied: jupyter-client>=5.3.1 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (5.3.4)
Requirement already satisfied: nbformat in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (4.4.0)
Requirement already satisfied: nbconvert in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (5.6.0)
Requirement already satisfied: terminado>=0.8.1 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (0.8.2)
Requirement already satisfied: prometheus-client in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (0.7.1)
Requirement already satisfied: ipython-genutils in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from notebook>=4.3.1->jupyterlab) (0.2.0)
Collecting json5
Using cached https://files.pythonhosted.org/packages/30/44/062543d4a6718f99d82e5ecf9140dbdee8a03122f2c34fbd0b0609891707/json5-0.8.5-py2.py3-none-any.whl
Requirement already satisfied: jsonschema>=3.0.1 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jupyterlab-server~=1.0.0->jupyterlab) (3.1.1)
Requirement already satisfied: decorator in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from traitlets>=4.2.1->notebook>=4.3.1->jupyterlab) (4.4.0)
Requirement already satisfied: six in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from traitlets>=4.2.1->notebook>=4.3.1->jupyterlab) (1.12.0)
Requirement already satisfied: pywin32>=1.0; sys_platform == "win32" in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jupyter-core>=4.4.0->notebook>=4.3.1->jupyterlab) (225)
Requirement already satisfied: ipython>=5.0.0 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from ipykernel->notebook>=4.3.1->jupyterlab) (7.8.0)
Requirement already satisfied: python-dateutil>=2.1 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jupyter-client>=5.3.1->notebook>=4.3.1->jupyterlab) (2.8.0)
Requirement already satisfied: entrypoints>=0.2.2 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from nbconvert->notebook>=4.3.1->jupyterlab) (0.3)
Requirement already satisfied: defusedxml in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from nbconvert->notebook>=4.3.1->jupyterlab) (0.6.0)
Requirement already satisfied: testpath in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from nbconvert->notebook>=4.3.1->jupyterlab) (0.4.2)
Requirement already satisfied: pygments in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from nbconvert->notebook>=4.3.1->jupyterlab) (2.4.2)
Requirement already satisfied: pandocfilters>=1.4.1 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from nbconvert->notebook>=4.3.1->jupyterlab) (1.4.2)
Requirement already satisfied: bleach in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from nbconvert->notebook>=4.3.1->jupyterlab) (3.1.0)
Requirement already satisfied: mistune<2,>=0.8.1 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from nbconvert->notebook>=4.3.1->jupyterlab) (0.8.4)
Requirement already satisfied: pywinpty>=0.5; os_name == "nt" in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from terminado>=0.8.1->notebook>=4.3.1->jupyterlab) (0.5.5)
Requirement already satisfied: pyrsistent>=0.14.0 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jsonschema>=3.0.1->jupyterlab-server~=1.0.0->jupyterlab) (0.15.4)
Requirement already satisfied: attrs>=17.4.0 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jsonschema>=3.0.1->jupyterlab-server~=1.0.0->jupyterlab) (19.3.0)
Requirement already satisfied: setuptools in c:\program files\windowsapps\pythonsoftwarefoundation.python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\lib\site-packages (from jsonschema>=3.0.1->jupyterlab-server~=1.0.0->jupyterlab) (41.2.0)
Requirement already satisfied: importlib-metadata in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jsonschema>=3.0.1->jupyterlab-server~=1.0.0->jupyterlab) (0.23)
Requirement already satisfied: backcall in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.1.0)
Requirement already satisfied: pickleshare in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.7.5)
Requirement already satisfied: jedi>=0.10 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.15.1)
Requirement already satisfied: colorama; sys_platform == "win32" in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.4.1)
Requirement already satisfied: prompt-toolkit<2.1.0,>=2.0.0 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (2.0.10)
Requirement already satisfied: webencodings in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from bleach->nbconvert->notebook>=4.3.1->jupyterlab) (0.5.1)
Requirement already satisfied: zipp>=0.5 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from importlib-metadata->jsonschema>=3.0.1->jupyterlab-server~=1.0.0->jupyterlab) (0.6.0)
Requirement already satisfied: parso>=0.5.0 in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from jedi>=0.10->ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.5.1)
Requirement already satisfied: wcwidth in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from prompt-toolkit<2.1.0,>=2.0.0->ipython>=5.0.0->ipykernel->notebook>=4.3.1->jupyterlab) (0.1.7)
Requirement already satisfied: more-itertools in c:\users\hasan\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from zipp>=0.5->importlib-metadata->jsonschema>=3.0.1->jupyterlab-server~=1.0.0->jupyterlab) (7.2.0)
Installing collected packages: json5, jupyterlab-server, jupyterlab
WARNING: The script pyjson5.exe is installed in 'C:\Users\HASAN\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts jlpm.exe, jupyter-lab.exe, jupyter-labextension.exe and jupyter-labhub.exe are installed in 'C:\Users\HASAN\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed json5-0.8.5 jupyterlab-1.1.4 jupyterlab-server-1.0.6
C:\Users\HASAN>jupyter notebook
'jupyter' is not recognized as an internal or external command,
operable program or batch file.
可能会发生暗模式更改!
答案 7 :(得分:0)
此扩展程序可帮助您更改状态栏文本的颜色,并且还支持iOS 13 https://stackoverflow.com/a/59767435/10512612
答案 8 :(得分:0)
如果其他人发现上述答案都不起作用(就像我所做的那样),如果您在 UIWindowScene
中有多个窗口,它将使用最顶层的窗口而不是键,则存在一个非常特殊的边缘情况用于确定状态栏外观的窗口。
例如,如果您将 windowLevel
设置为 1
的关键窗口和 windowLevel
设置为 1.1
的辅助窗口,UIKit 将(对于无论出于何种原因)询问您次要窗口中的视图控制器的状态栏外观,而不是关键窗口中的视图控制器,即使其 alpha 为 0。
我们的解决方法是仅在辅助窗口处于活动状态时将其置于较高级别,并在其隐藏时将其降低到关键窗口下方。