[英]Vertical orientation and landscape orientation are different in the Xcode simulator
When I run my code and start the simulator, vertical orientation looks good, but when I turn to landscape orientation, the name in the display cuts.当我运行我的代码并启动模拟器时,垂直方向看起来不错,但是当我转向横向时,显示中的名称会消失。
import SwiftUI
struct ContentView: View {
@Environment(\.horizontalSizeClass) var hSizeClass
@Environment(\.verticalSizeClass) var vSizeClass
var body: some View {
if hSizeClass == .compact && vSizeClass == .regular {
compactDesign()
}else {
regularDesign()
}
} }
struct compactDesign: View {
var body: some View{
ZStack {
Color.green.edgesIgnoringSafeArea(.all)
VStack(){
Image("Icono")
.resizable()
.frame(width: 80, height: 80, alignment: .center)
.clipShape(Circle())
Text("María Ramirez")
.font(.largeTitle)
.foregroundColor(.white)
.bold()
Text("Calle #123")
.foregroundColor(.white).font(.title).italic()
}
}
} }
struct regularDesign: View {
var body: some View{
ZStack {
Color.blue.edgesIgnoringSafeArea(.all)
HStack(){
Image("Icono")
.resizable()
.frame(width: 80, height: 80, alignment: .center)
VStack(alignment: .leading, spacing: 10){
Text("María Ramirez")
.font(.largeTitle)
.foregroundColor(.white)
.bold()
.clipShape(Circle())
Text("Calle #123")
.foregroundColor(.white).font(.title).italic()
}
}
}
} }
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
} }
You need to be careful with your modifiers.你需要小心你的修饰符。 You put the
.clipShape()
on to your Text()
, not the Image
.您将
.clipShape()
放在Text()
上,而不是Image
上。 Also, be consistent with your code.此外,请与您的代码保持一致。 If you chain modifiers on one line, do the same thing on the other lines.
如果您在一行上链接修饰符,请在其他行上执行相同的操作。 If you have them on separate lines, keep them on separate lines.
如果您将它们放在不同的行上,请将它们放在不同的行上。 It makes your code easier to follow.
它使您的代码更易于遵循。 Lastly, when posting code like this with an image we don't have, substitute a
Rectangle()
for it to make it easier to run for ourselves.最后,当使用我们没有的图像发布这样的代码时,用
Rectangle()
代替它,以便我们自己运行。
struct regularDesign: View {
var body: some View{
ZStack {
Color.blue.edgesIgnoringSafeArea(.all)
HStack {
Image("Icono")
.resizable()
.frame(width: 80, height: 80, alignment: .center)
.clipShape(Circle()) // <- To here
VStack(alignment: .leading, spacing: 10){
Text("María Ramirez")
.font(.largeTitle)
.foregroundColor(.white)
.bold()
//.clipShape(Circle()) <- Move This
Text("Calle #123")
.foregroundColor(.white)
.font(.title)
.italic()
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.