swiftui

SwiftUI Mac OS how to add selection to the List view

巧了我就是萌 提交于 2020-12-10 08:57:12
问题 It easy to create a simple list like this: List { Text("Item 1") Text("Item 2") Text("Item3") } But how I can add a selection like traditional NSTable? 回答1: struct names { var id = 0 var name = "" } var demoData = ["Phil Swanson", "Karen Gibbons", "Grant Kilman", "Wanda Green"] struct SelectionDemo : View { @State var selectKeeper = Set<String>() var body: some View { HStack { List(demoData, id: \.self, selection: $selectKeeper){ name in Text(name) }.frame(width: 500, height: 460) } } } #if

SwiftUI Mac OS how to add selection to the List view

独自空忆成欢 提交于 2020-12-10 08:57:04
问题 It easy to create a simple list like this: List { Text("Item 1") Text("Item 2") Text("Item3") } But how I can add a selection like traditional NSTable? 回答1: struct names { var id = 0 var name = "" } var demoData = ["Phil Swanson", "Karen Gibbons", "Grant Kilman", "Wanda Green"] struct SelectionDemo : View { @State var selectKeeper = Set<String>() var body: some View { HStack { List(demoData, id: \.self, selection: $selectKeeper){ name in Text(name) }.frame(width: 500, height: 460) } } } #if

SwiftUI: Sheet cannot show correct values in first time

☆樱花仙子☆ 提交于 2020-12-10 08:45:28
问题 I found strange behavior in SwiftUI. The sheet shows empty text when I tap a list column first time. It seems correct after second time. Would you help me? import SwiftUI let fruits: [String] = [ "Apple", "Banana", "Orange", ] struct ContentView: View { @State var isShowintSheet = false @State var selected: String = "" var body: some View { NavigationView { List(fruits, id: \.self) { fruit in Button(action: { selected = fruit isShowintSheet = true }) { Text(fruit) } } } .sheet(isPresented:

SwiftUI: Sheet cannot show correct values in first time

一笑奈何 提交于 2020-12-10 08:45:10
问题 I found strange behavior in SwiftUI. The sheet shows empty text when I tap a list column first time. It seems correct after second time. Would you help me? import SwiftUI let fruits: [String] = [ "Apple", "Banana", "Orange", ] struct ContentView: View { @State var isShowintSheet = false @State var selected: String = "" var body: some View { NavigationView { List(fruits, id: \.self) { fruit in Button(action: { selected = fruit isShowintSheet = true }) { Text(fruit) } } } .sheet(isPresented:

SwiftUI: Broken explicit animations in NavigationView?

℡╲_俬逩灬. 提交于 2020-12-10 07:38:09
问题 When I put an explicit animation inside a NavigationView, as an undesirable side effect, it animates the initial layout of the NavigationView content. It gets especially bad with infinite animations. Is there a way to disable this side effect? Example: the image below is supposed to be an animated red loader on a full screen blue background. Instead I get this infinite loop of a scaling blue background: import SwiftUI struct EscapingAnimationTest: View { var body: some View { NavigationView {

Mac OS X - SwiftUI - how to draw a String (text) together with some path

两盒软妹~` 提交于 2020-12-10 05:27:35
问题 I'm trying to adopt one of my old programs to new SwitUI. I could not find a way to draw the text on a graph. Below example is displaying two lines (in reality it will be some sort of oscilloscope showing real time voltage changes). To keep the story short. below fragment is drawing two lines and then I want to have some description "label" on it. Lines are drawn correctly but then cannot get any text. UIGraphics is not available on Mac OS applications. For last three days I'm googling a lot.

Mac OS X - SwiftUI - how to draw a String (text) together with some path

二次信任 提交于 2020-12-10 05:24:27
问题 I'm trying to adopt one of my old programs to new SwitUI. I could not find a way to draw the text on a graph. Below example is displaying two lines (in reality it will be some sort of oscilloscope showing real time voltage changes). To keep the story short. below fragment is drawing two lines and then I want to have some description "label" on it. Lines are drawn correctly but then cannot get any text. UIGraphics is not available on Mac OS applications. For last three days I'm googling a lot.

What does 'identity' mean in SwifUI and how do we change the 'identity' of something

℡╲_俬逩灬. 提交于 2020-12-09 09:51:28
问题 I'm new to SwiftUI and I'm having problems with presenting Alerts back-to-back. The description of the .alert(item:content:) modifier has this written in it's definition: /// Presents an alert. /// /// - Parameters: /// - item: A `Binding` to an optional source of truth for the `Alert`. /// When representing a non-nil item, the system uses `content` to /// create an alert representation of the item. /// /// If the identity changes, the system will dismiss a /// currently-presented alert and

What does 'identity' mean in SwifUI and how do we change the 'identity' of something

五迷三道 提交于 2020-12-09 09:47:18
问题 I'm new to SwiftUI and I'm having problems with presenting Alerts back-to-back. The description of the .alert(item:content:) modifier has this written in it's definition: /// Presents an alert. /// /// - Parameters: /// - item: A `Binding` to an optional source of truth for the `Alert`. /// When representing a non-nil item, the system uses `content` to /// create an alert representation of the item. /// /// If the identity changes, the system will dismiss a /// currently-presented alert and

How to set the title of a NavigationView in SwiftUI to large title (or small)?

北慕城南 提交于 2020-12-08 07:21:38
问题 Using SwiftUI how do I change the navigation bar's title size? Choosing between a standard or a large title. 回答1: SwiftUI (Xcode 11.3) SwiftUI navigationBarTitle modifier has an optional displayMode property which you can set to .inline for small titles and .large for large titles. See documentation NavigationView { TopLevelView { // […] } .navigationBarTitle("Test", displayMode: .inline) // ⬅️ Important part } How it's done in UIKit Since iOS 11, UINavigationBar can display its title in