我希望在 iOS 13 Dark Mode 中控制状态栏文本颜色。当不打开暗模式时,我可以通过设置 Scaffold 的 AppBar 属性“亮度”来更改状态栏颜色。代码如下:
return Scaffold(
appBar: AppBar(
brightness: Brightness.light, //<--Here!!!
title: Text(widget.title),
),
...
Run Code Online (Sandbox Code Playgroud)
努力是这样的:
但是当我启用模拟器的暗模式时,该方法不起作用。打开模拟器的“Dark Appearance”:
打开“Dark Appearance”后,状态栏文字颜色无法通过该方法改变,只是白色(亮度模式)。
我尝试过这些方法来更改状态栏文本颜色:
方法一:
void main() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
runApp(MyApp());
}
Run Code Online (Sandbox Code Playgroud)
方法二:
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: Material(
child: Scaffold(
appBar: AppBar(
brightness: Brightness.light,
title: Text(widget.title),
),
body: Center(
Run Code Online (Sandbox Code Playgroud)
但他们都无法工作。
希望您的帮助!谢谢你。
更新Xcode11 beta3后,我发现scrollview内部视图的阴影会在边界处被切断,但在Xcode11 beta2中没有问题。我只是使用底部填充来修复它,但我认为这不是一个好的解决方案。有没有其他解决方案来解决这个问题?
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 30) {
ForEach(courses) { item in
PresentationLink(destination: ContentView()) {
CourseView(
title: item.title,
image: item.image,
color: item.color,
shadowColor: item.shadowColor
)
}
}
}
.padding(.leading, 40)
.padding(.bottom, 60)
Run Code Online (Sandbox Code Playgroud)
CourseView() 有一个阴影修饰符,定义的主体就像:
var body: some View {
return VStack(alignment: .leading) {
Text(title)
.font(.title)
.fontWeight(.bold)
.color(.white)
.padding(30)
.lineLimit(4)
.padding(.trailing, 50)
Spacer()
Image(image)
.resizable()
.renderingMode(.original)
.aspectRatio(contentMode: .fit)
.frame(width: 246, height: 150)
.padding(.bottom, 30)
}
.background(color)
.cornerRadius(30)
.frame(width: 246, height: 360)
.shadow(color: shadowColor, radius: 20, x:0, y: 20)
} …
Run Code Online (Sandbox Code Playgroud) 我想隐藏 SwiftUI 中的状态栏。我尝试过“statusBar(hidden: true)”方法,但它不起作用。是否有任何解决方案可以在 SwiftUI 中实现。
演示代码如下:
var body: some View {
VStack {
Text("Hello World")
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.blue)
.edgesIgnoringSafeArea(.all)
.statusBar(hidden: true)
}
Run Code Online (Sandbox Code Playgroud)