다음은 텍스트가있는 두 개의 상자가 SwiftUI에서 렌더링되는 방식이지만 둘 다 전체 너비가되기를 원합니다.
내 코드는 다음과 같습니다.
VStack(spacing: 20){
//Help ---
VStack(alignment: .leading, spacing:10){
Text("Help").h2()
Text("Please view our online user guide before contacting us since we answer most questions there.")
.lineLimit(nil) //Make the text wrap
.prefsText()
Button("Online Help"){
openURL(URL(string: "https://avid.pro/help")!)
}.foregroundColor(Color(accentColor))
.buttonStyle(PlainButtonStyle())
.prefsLink()
}.unoBoxRoundPad()
.frame(maxWidth: .infinity)
//Support ---
VStack(alignment: .leading, spacing:10){
Text("Support").h2()
Text("Email us if you need to submit a bug or get specialized help. It may take us a few days to get back to you.")
.lineLimit(nil) //Make the text wrap
.prefsText()
Button("Email Us"){
openURL(URL(string: "mailto:[email protected]")!)
}.foregroundColor(Color(accentColor))
.buttonStyle(PlainButtonStyle())
.prefsLink()
}.unoBoxRoundPad()
.frame(maxWidth: .infinity)
}.background(Color.yellow) //For testing
나는 그들이 같은 너비가 아닌 이유를 내 인생에서 알 수 없습니다. .unoBoxRoundPad()
다음 공유 스타일을 추가하는보기 수정 자입니다.
.padding(20)
.background(Color("UnoDark"))
.cornerRadius(7)
포함 .frame(maxWidth: .infinity)
하는 Text()
대신 에을 넣으면 VStack
조금 더 가까워지는 것처럼 보이지만 포함하는 뷰의 다음을 무시합니다 padding()
.
내가 뭘 잘못하고 있는지에 대한 아이디어가 있습니까?
여기에는 두 가지 문제가 있습니다.
You've got two modifiers swapped (.frame(...)
and .unoBoxRoundPad()
); you want the roundedness to apply to the entire stretched thing. By putting .unoBoxRoundPad()
first, you're saying "pad this thing" and then "place that rounded thing inside an infinitely-wide box"; you want the reverse: your thing should be placed inside an infinitely-wide box, and it's the infinitely wide box that should have the rounded corners and padding.
alignment:
해당 .frame()
수정자를 사용할 때 를 지정해야합니다 . 내부 뷰가 무한 넓이의 상자 안에 배치되면 기본적으로 내부에 수직 및 수평으로 중앙에 위치하게됩니다. 스크린 샷을 기반으로 .topLeading
콘텐츠 ( "지원", "도움말"등)가 왼쪽 상단 (또는 RTL 언어의 오른쪽 상단)에서 시작되도록 사용하고 싶을 것입니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다