Questions tagged [swiftui]

SwiftUI is a way to build user interfaces across all Apple platforms. Build user interfaces for any Apple device using one set of tools and APIs. With a declarative Swift syntax that’s easy to read and natural to write, SwiftUI works seamlessly with Xcode design tools to keep your code and design perfectly in sync. Automatic support for Dynamic Type, Dark Mode, localization, and accessibility. Use this tag for questions about SwiftUI on any platform.

SwiftUI is a closed-source Apple framework providing a declarative Swift-only API for defining the appearance and behavior of graphical user interfaces. Apple's reference documentation describes SwiftUI as follows:

SwiftUI provides views, controls, and layout structures for declaring your app's user interface. The framework provides event handlers for delivering taps, gestures, and other types of input to your app, and tools to manage the flow of data from your app's models down to the views and controls that users will see and interact with.

Though apps can now be built fully with SwiftUI, using the SwiftUI lifecycle, one can also embed the top-level SwiftUI View in an appropriate hosting adapter for the platform (NSHostView, NSHostingController, UIHostingController, or WKHostingController) for apps with non-SwiftUI lifecycles.

SwiftUI integrates with Apple's older imperative AppKit, UIKit, and WatchKit frameworks. An NSView or UIView can embed a SwiftUI View and vice versa.

SwiftUI supports live previews and dynamic replacement (hot swapping) in Xcode 11 on macOS 10.15 (Catalina) and later, and on devices running an operating system that supports SwiftUI (see the list below).

Apple first revealed SwiftUI at WWDC on June 3, 2019 and made it available in the first beta release of Xcode 11.

SwiftUI is part of the following SDKs:

  • macOS 10.15 (Catalina) and later,
  • iOS 13 and later,
  • tvOS 13 and later,
  • watchOS 6 and later.

SwiftUI apps cannot be deployed to older platforms.

In addition to the official documentation, Apple offers two tutorials (Introducing SwiftUI and the first part of Develop Apps for iOS) entirely devoted to SwiftUI, as well as sample code (Fruta: Building a Feature-Rich App with SwiftUI).

35593 questions
11
votes
1 answer

SwiftUI add a -y offset to a view but stretching the view to bottom

I have 2 views in my code, a VStack and then a custom view. I am adding an offset to the second view of -75, to move it on top of the first view. Here is my current code: Group { VStack { //First View VStack { …
Matt Ward
  • 1,095
  • 1
  • 14
  • 28
11
votes
1 answer

Is there a SwiftUI equivalent for lineBreakMode for Text views?

I have a Text view, and I would like to configure it to wrap the first character that doesn't fit. In UIKit, this would be the equivalent of setting label.lineBreakMode = .byCharWrapping. Has this been implemented for SwiftUI Text yet? I haven't…
Eugene
  • 3,417
  • 5
  • 25
  • 49
11
votes
2 answers

Screen Background Color With ScrollView And Navigation Bar SwiftUI

Im trying to have a colored background while using a scrollview with SwiftUI but this causes the navigation title to no longer collapse. I've tried a number of ways yet this is always an issue. struct Person : Identifiable{ var id : Int var…
Richard Witherspoon
  • 4,082
  • 3
  • 17
  • 33
11
votes
4 answers

SwiftUI strange behavior when moving items between sections in a List

so I've been trying to make a component using swiftUI that allows you to move items in a List between sections. I prepared an example with two sections: "First List" and "Second List". Whenever you tap on an item it swaps sections. Here's a…
SwiftedMind
  • 3,701
  • 3
  • 29
  • 63
11
votes
3 answers

How to get the keyboard height on multiple screens with SwiftUI and move the button

The following code gets the keyboard height when the keyboard is displayed and moves the button by the keyboard height. This movement is performed in the same way at the transition source (ContentView) and the transition destination…
Ika
  • 1,271
  • 1
  • 12
  • 20
11
votes
1 answer

How to change background color of the NavigationView in SwiftUI?

I'm trying to change background color of the NavigationView (not navigation bar) using this code: NavigationView { Text("Text") } .background(Color.clear) But it doesn't work. Also, I tried to change UIView…
Ilya Kharabet
  • 4,203
  • 3
  • 15
  • 29
11
votes
2 answers

SwiftUI fullscreen image background

I want to have a full screen image in the background. I have implemented this: struct LoginView: View { var body: some View { VStack { Spacer(); Text("Hallo"); Text("Hallo2"); …
CodierGott
  • 471
  • 1
  • 5
  • 10
11
votes
2 answers

How to show a AVCaptureVideoPreviewLayer in SwiftUI

In previous versions of swift, you create a AVCaptureVideoPreviewLayer in a ViewController and add it to the default view using view.layer.addSublayer(previewLayer). How is this done in SwiftUI ContentView? None of the View types in SwiftUI appear…
Tim
  • 597
  • 8
  • 18
11
votes
4 answers

SwiftUI - Align contents of Button to the left

I have a design that looks like this: When I wrap it in a Button, the Image and "HOME" text move toward the center: I am trying to keep the contents aligned to the left but I'm having trouble. Here's the code that makes up this component. struct…
natecraft1
  • 2,737
  • 9
  • 36
  • 56
11
votes
3 answers

Change to @Published var in @EnvironmentObject not reflected immediately

In this specific case, when I try to change an @EnvironmentObject's @Published var, I find that the view is not invalidated and updated immediately. Instead, the change to the variable is only reflected after navigating away from the modal and…
Zain
  • 1,569
  • 1
  • 13
  • 19
11
votes
3 answers

SwiftUI: How to have HStack wrap children along multiple lines (like a collection view)?

I'm trying to recreate basic collection view behavior with SwiftUI: I have a number of views (e.g. photos) that are shown next to each other horizontally. When there is not enough space to show all photos on the same line, the remaining photos…
Mark
  • 6,647
  • 1
  • 45
  • 88
11
votes
2 answers

After upgrade to iOS13 beta 6/Xcode 11 beta 5: issue "dyld: Symbol not found: _$s7SwiftUI7BindingVyxGAA0C11ConvertibleAAMc"

After upgrading to iOS13 beta 6 using Xcode 11 beta 5 I receive this message when running on an iPhone SE device. dyld: Symbol not found: _$s7SwiftUI7BindingVyxGAA0C11ConvertibleAAMc Referenced from:…
AnErd
  • 415
  • 3
  • 12
11
votes
2 answers

How to change text color of actionSheet in SwiftUI

I am trying to change color of actionSheet's text in SwiftUI. Unable to do so. I tried following code private var actionSheet: ActionSheet { let button1 = ActionSheet.Button.default(Text("Week 1").foregroundColor(.orange)) { …
Lalli
  • 436
  • 5
  • 12
11
votes
2 answers

Implementing Page Based Navigation for SwiftUI Apple Watch App

I'm building an Apple Watch app in SwiftUI and would like to implement page based navigation so when users swipe left on the home screen, they are taken to another view. I understand how to use NavigationLink to let users move from one screen to…
Ryan
  • 630
  • 8
  • 20
11
votes
4 answers

SwiftUI: set background color of the presenting view of a sheet

Is there a way I can specify the background color of the view used to display a sheet in SwiftUI? I know I can set .background on my view, but on iPhone X that doesn't affect the safe area. I also could use .edgesIgnoringSafeArea to fill the area,…
keegan3d
  • 10,357
  • 9
  • 53
  • 77