文字会被SwiftUI剪切,但是为什么呢?

时间:2019-10-31 18:19:25

标签: swiftui

您可以将其直接复制到Playground中,您会看到文本被剪切,但是我不知道为什么要剪切?我该如何预防?

import SwiftUI
import PlaygroundSupport

struct ContentView: View {
    var body: some View {
        VStack(alignment: .leading) {

            Text("Background").font(.title).padding()
            Text("Ahmad Shah DURRANI unified the Pashtun tribes and founded Afghanistan in 1747. The country served as a buffer between the British and Russian Empires until it won independence from notional British control in 1919. A brief experiment in democracy ended in a 1973 coup and a 1978 communist countercoup. The Soviet Union invaded in 1979 to support the tottering Afghan communist regime, touching off a long and destructive war. The USSR withdrew in 1989 under relentless pressure by internationally supported anti-communist mujahidin rebels. A series of subsequent civil wars saw Kabul finally fall in 1996 to the Taliban, a hardline Pakistani-sponsored movement that emerged in 1994 to end the country's civil war and anarchy. Following the 11 September 2001 terrorist attacks, a US, Allied, and anti-Taliban Northern Alliance military action toppled the Taliban for sheltering Usama BIN LADIN.\nA UN-sponsored Bonn Conference in 2001 established a process for political reconstruction that included the adoption of a new constitution, a presidential election in 2004, and National Assembly elections in 2005. In December 2004, Hamid KARZAI became the first democratically elected president of Afghanistan, and the National Assembly was inaugurated the following December. KARZAI was reelected in August 2009 for a second term. The 2014 presidential election was the country's first to include a runoff, which featured the top two vote-getters from the first round, Abdullah ABDULLAH and Ashraf GHANI. Throughout the summer of 2014, their campaigns disputed the results and traded accusations of fraud, leading to a US-led diplomatic intervention that included a full vote audit as well as political negotiations between the two camps. In September 2014, GHANI and ABDULLAH agreed to form the Government of National Unity, with GHANI inaugurated as president and ABDULLAH elevated to the newly-created position of chief executive officer. The day after the inauguration, the GHANI administration signed the US-Afghan Bilateral Security Agreement and NATO Status of Forces Agreement, which provide the legal basis for the post-2014 international military presence in Afghanistan. After two postponements, the next presidential election has been re-scheduled for September 2019.\nThe Taliban remains a serious challenge for the Afghan Government in almost every province. The Taliban still considers itself the rightful government of Afghanistan, and it remains a capable and confident insurgent force fighting for the withdrawal of foreign military forces from Afghanistan, establishment of sharia law, and rewriting of the Afghan constitution. In 2019, negotiations between the US and the Taliban in Doha entered their highest level yet, building on momentum that began in late 2018. Underlying the negotiations is the unsettled state of Afghan politics, and prospects for a sustainable political settlement remain unclear.").lineLimit(5000).padding()
            Text("another")
            Text("text")
        }
    }
}


PlaygroundPage.current.setLiveView(ContentView())

1 个答案:

答案 0 :(得分:1)

我认为这与SwiftUI如何根据可用屏幕空间呈现VStack有关。您会期望大的Text会占用剩余的空间,而看不到最后两个Texts。但是,您可以看到它们,并且大Text已被截断。我认为VStack试图适应屏幕上的所有项目。如果您在大Text之后添加其他项,则它会进一步截断大Text

Truncated text

设置.framemaxHeight的{​​{1}}无效。

但是,如果将.infinity包裹在VStackScrollView中,则会显示全文。

如果您不希望文本有行数限制,则可以按照文档中的说明将List传递给它,而不用选择任意大的数字。

  

如果为nil,则没有行数限制。

nil