[英]Show color on full screen in SwiftUI
I'm trying to show red color in full screen.我正在尝试全屏显示红色。
If I use edgesIgnoringSafeArea(.all)
the screen automatically becomes scrolling enabled, which I don't want.如果我使用
edgesIgnoringSafeArea(.all)
屏幕会自动启用滚动,这是我不想要的。 Can you please advise me how to show red color on full screen without scrolling and without stretching because i change the color to image.你能告诉我如何在不滚动和不拉伸的情况下全屏显示红色,因为我将颜色更改为图像。
Any help would be greatly appreciated.任何帮助将不胜感激。
Sample code is given below.示例代码如下。
import SwiftUI
struct PageSetup: View {
@State private var tabSelection = 0
var body: some View {
ZStack {
TabView(selection: $tabSelection) {
ForEach(0..<5) { index in
ZStack {
Color.red
Text("\(index)")
}
}
}
.tabViewStyle(PageTabViewStyle())
.onAppear {
UIScrollView.appearance().bounces = false
}
.tabViewStyle(PageTabViewStyle())
}
}
}
Output Output
If I understood what you wanted correctly, you are using ZStack
and Color
in wrong place.如果我正确理解了您想要什么,那么您在错误的地方使用了
ZStack
和Color
。 Your body
should be like this code sample.你的
body
应该像这个代码示例。
struct PageSetup: View {
@State private var tabSelection = 0
var body: some View {
ZStack {
getColorForPage().ignoresSafeArea()
TabView (selection: $tabSelection) {
ForEach(0..<5){ index in
Text("\(index)")
}
}
.tabViewStyle(PageTabViewStyle())
.onAppear {
UIScrollView.appearance().bounces = false
}
}
}
func getColorForPage() -> Color {
if tabSelection == 0 {
return Color.red
} else if tabSelection == 1 {
return Color.blue
} else {
return Color.orange
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.