На мой взгляд, у меня есть изображение, с которым я всегда отображается, и какой -то текст под ним, который должен быть вертикально прокручивать. Этот текст может быть коротким или длинным. сверху, поэтому текст может получить больше места. верхняя часть экрана.
struct ContentView: View {
let longText: String = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
let shortText: String = "This is short text"
var body: some View {
VStack {
Image(systemName: "photo").resizable().aspectRatio(contentMode: .fit).frame(width: 30, height: 20)
/// Note: This shows both elements image and text in the center of the view.
// Text(shortText).font(.body)
// .foregroundStyle(Color.primary)
// .multilineTextAlignment(.center)
// .padding(.top, 20.0)
// .padding([.leading, .trailing], 25.0)
/// Note: Scrollview pushes the image and text on top.
ScrollView(showsIndicators: false) {
Text(shortText).font(.body)
.foregroundStyle(Color.primary)
.multilineTextAlignment(.center)
.padding(.top, 20.0)
.padding([.leading, .trailing], 25.0)
}
}
.padding(.top, 20.0)
}
}
короткий текст без просмотра прокрутки (это то, что я хочу, чтобы представление всегда искало короткий текст, то есть даже при представлении прокрутки):
Так выглядит представление в настоящее время с просмотром прокрутки и коротким текстом (я хочу, чтобы изображение и текст были центрированы так же, как и изображение выше, даже когда присутствует просмотр прокрутки) < /p>
Просмотр с изображением и длинным текстом (это, как и ожидалось, когда присутствует длинный текст)
Как я могу сохранить изображение и текстовый центр для более мелких текстов даже при просмотре прокрутки? Или есть другой способ достичь того, что я хочу?
На мой взгляд, у меня есть изображение, с которым я всегда отображается, и какой -то текст под ним, который должен быть вертикально прокручивать. Этот текст может быть коротким или длинным. сверху, поэтому текст может получить больше места. верхняя часть экрана. [code]struct ContentView: View { let longText: String = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
let shortText: String = "This is short text"
var body: some View { VStack { Image(systemName: "photo").resizable().aspectRatio(contentMode: .fit).frame(width: 30, height: 20)
/// Note: This shows both elements image and text in the center of the view. // Text(shortText).font(.body) // .foregroundStyle(Color.primary) // .multilineTextAlignment(.center) // .padding(.top, 20.0) // .padding([.leading, .trailing], 25.0)
/// Note: Scrollview pushes the image and text on top. ScrollView(showsIndicators: false) { Text(shortText).font(.body) .foregroundStyle(Color.primary) .multilineTextAlignment(.center) .padding(.top, 20.0) .padding([.leading, .trailing], 25.0) } } .padding(.top, 20.0) } } [/code] [b] короткий текст без просмотра прокрутки (это то, что я хочу, чтобы представление всегда искало короткий текст, то есть даже при представлении прокрутки): [/b]
[b] Так выглядит представление в настоящее время с просмотром прокрутки и коротким текстом (я хочу, чтобы изображение и текст были центрированы так же, как и изображение выше, даже когда присутствует просмотр прокрутки) [/b] < /p>
[b] Просмотр с изображением и длинным текстом (это, как и ожидалось, когда присутствует длинный текст) [/b]
Как я могу сохранить изображение и текстовый центр для более мелких текстов даже при просмотре прокрутки? Или есть другой способ достичь того, что я хочу?
На мой взгляд, у меня есть изображение, с которым я всегда отображается, и какой -то текст под ним, который должен быть вертикально прокручивать. Этот текст может быть коротким или длинным. сверху, поэтому текст может получить больше места. верхняя...
У меня есть проблема с тем, чтобы сохранить представление списка «замороженное», когда добавляются новые элементы, если пользователь прокручивается вниз, чтобы просмотреть и элемент. Вот код, который я в настоящее время использую:
import SwiftUI...
У меня есть серия анимаций, которая заканчивается тем, что текст и изображение анимированы вверх (подумайте о повествовании Starwars). Однако, когда анимация будет завершена, я могу продолжать прокручивать страницу с другим контентом, но я не могу...
У меня проблема. UiKitView перемещается в верхнюю часть экрана, когда я вызываю метод отклонения класса PKAddPaymentPassViewControllerDelegate. Вы столкнулись с этой проблемой? Когда пользователь нажимает кнопку отмены приложения Apple Wallet,...
На уроке информатики мне поручили написать мод для базовой программы игры со змеями. Я решил добавить функцию, при которой, когда пользователь нажимает кнопку ПРОБЕЛ, он будет открывать портал в зависимости от того, в каком режиме находится...