swiftui

SwiftUI WidgetKit: How to anchor views to the top

筅森魡賤 提交于 2021-02-07 10:00:22
问题 I am attempting to layout a tableView using SwiftUI and WidgetKit and would like to achieve a similar result of that as the Apple's Notes widget. My current implementation succeeds in laying out the view in the .systemLarge widget, but not in the .systemMedium widget. I would like to pin the view to the top of the widget, such that the header of "FAVOURITES" is visible in the .systemMedium . struct PlacesWidgetEntryView : View { var entry: Provider.Entry let places = [ Place(name: "Place 1",

How can I add something like a “subheader” into the navigation bar in SwiftUI?

醉酒当歌 提交于 2021-02-07 09:51:18
问题 "My" solution: Thanks to the help of Midhun MP and Mojtaba Hosseini I found this solution. It works ok, but the translucent effect of the navigation bar does not work anymore. So, if anyone knows how to fix it, please let me know. // UITableView.appearance().backgroundColor = UIColor(named: "CustomTableViewBackgroundColor") // These are all custom color sets // UITableViewCell.appearance().backgroundColor = UIColor(named: "CustomTableViewCellBackgroundColor") // For the navigation bar color

How can I add something like a “subheader” into the navigation bar in SwiftUI?

僤鯓⒐⒋嵵緔 提交于 2021-02-07 09:50:14
问题 "My" solution: Thanks to the help of Midhun MP and Mojtaba Hosseini I found this solution. It works ok, but the translucent effect of the navigation bar does not work anymore. So, if anyone knows how to fix it, please let me know. // UITableView.appearance().backgroundColor = UIColor(named: "CustomTableViewBackgroundColor") // These are all custom color sets // UITableViewCell.appearance().backgroundColor = UIColor(named: "CustomTableViewCellBackgroundColor") // For the navigation bar color

SwiftUI reorder CoreData Objects in List

霸气de小男生 提交于 2021-02-07 07:16:53
问题 I want to change the order of the rows in a list that retrieves objects from the core data. Moving rows works, but the problem is that I can't save the changes. I don't know how to save the changed Index of the CoreData Object. Here is my Code: Core Data Class: public class CoreItem: NSManagedObject, Identifiable{ @NSManaged public var name: String } extension CoreItem{ static func getAllCoreItems() -> NSFetchRequest <CoreItem> { let request: NSFetchRequest<CoreItem> = CoreItem.fetchRequest()

SwiftUI reorder CoreData Objects in List

限于喜欢 提交于 2021-02-07 07:16:39
问题 I want to change the order of the rows in a list that retrieves objects from the core data. Moving rows works, but the problem is that I can't save the changes. I don't know how to save the changed Index of the CoreData Object. Here is my Code: Core Data Class: public class CoreItem: NSManagedObject, Identifiable{ @NSManaged public var name: String } extension CoreItem{ static func getAllCoreItems() -> NSFetchRequest <CoreItem> { let request: NSFetchRequest<CoreItem> = CoreItem.fetchRequest()

How do I bind a SwiftUI element to a value in a Dictionary?

爱⌒轻易说出口 提交于 2021-02-07 06:12:36
问题 I have a dictionary that contains various values I want to "filter" by. So I'm doing something like this struct ExampleView : View { @EnvironmentObject var externalData : ExternalData var body: some View { VStack { ForEach(externalData.filters) { (v : (String, Bool)) in Toggle(isOn: $externalData.filters[v.0], label: { Text("\(v.0)") }) } } } } final class ExternalData : BindableObject { let didChange = PassthroughSubject<ExternalData, Never>() init() { filters["Juniper"] = true filters[

How do I bind a SwiftUI element to a value in a Dictionary?

烂漫一生 提交于 2021-02-07 06:09:10
问题 I have a dictionary that contains various values I want to "filter" by. So I'm doing something like this struct ExampleView : View { @EnvironmentObject var externalData : ExternalData var body: some View { VStack { ForEach(externalData.filters) { (v : (String, Bool)) in Toggle(isOn: $externalData.filters[v.0], label: { Text("\(v.0)") }) } } } } final class ExternalData : BindableObject { let didChange = PassthroughSubject<ExternalData, Never>() init() { filters["Juniper"] = true filters[

How do I bind a SwiftUI element to a value in a Dictionary?

一曲冷凌霜 提交于 2021-02-07 06:08:57
问题 I have a dictionary that contains various values I want to "filter" by. So I'm doing something like this struct ExampleView : View { @EnvironmentObject var externalData : ExternalData var body: some View { VStack { ForEach(externalData.filters) { (v : (String, Bool)) in Toggle(isOn: $externalData.filters[v.0], label: { Text("\(v.0)") }) } } } } final class ExternalData : BindableObject { let didChange = PassthroughSubject<ExternalData, Never>() init() { filters["Juniper"] = true filters[

How can I get data from ObservedObject with onReceive in SwiftUI?

拈花ヽ惹草 提交于 2021-02-07 05:01:56
问题 In my SwiftUI app, I need to get data from ObservedObject each time the value change. I understood that we could do that with .onReceive? I don't understand well the documentation of Apple about it. I don't know how I can do this. My code: import SwiftUI import CoreLocation struct Compass: View { @StateObject var location = LocationManager() @State private var angle: CGFloat = 0 var body: some View { VStack { Image("arrow") .resizable() .aspectRatio(contentMode: .fit) .frame(width: 300,

Is it possible to change “return” key to “done” on keyboard in 2020 with SwiftUI?

我只是一个虾纸丫 提交于 2021-02-07 03:54:19
问题 I didn't find any link or guide to change the "return" key to "done" when keyboard open for TextField in SwiftUI. Is it possible now without customising UITextField? 回答1: The best way I found was to just add the package Introspect to your project. After doing so add in import Introspect anywhere in your project files. Then add one of their View Modifiers to your Textfield to achieve what you want. I believe this is what you want though ⤵ .introspectTextField { textfield in textfield