swiftui

SwiftUI: Manipulate single Items generated from “For - In” loop

强颜欢笑 提交于 2021-02-10 20:17:17
问题 Aloha, Introduction The idea is to create a quiz game in which you have a varying amount of buttons, one answer is "right" the others are "wrong". When selecting any button the color of the "right button" should turn green, the rest turn red. How the App works The App loads all the data from a Swift file called LectureTopics (See Below). LectureTopics is a struct that contains a lot of variables (ButtonText, ButtoneAnswerCorrect (Bool) Descriptions etc.) and an extension that holds the

SwiftUI: Manipulate single Items generated from “For - In” loop

被刻印的时光 ゝ 提交于 2021-02-10 20:15:58
问题 Aloha, Introduction The idea is to create a quiz game in which you have a varying amount of buttons, one answer is "right" the others are "wrong". When selecting any button the color of the "right button" should turn green, the rest turn red. How the App works The App loads all the data from a Swift file called LectureTopics (See Below). LectureTopics is a struct that contains a lot of variables (ButtonText, ButtoneAnswerCorrect (Bool) Descriptions etc.) and an extension that holds the

SwiftUI: Why is the height of proxy.safeAreaInsets.bottom equal to keyboardHeight?

核能气质少年 提交于 2021-02-10 20:13:11
问题 So the safeAreaInset.bottom on the iPhone 11 Pro Max is 34.0, but when the keyboard is open, it changes the safeAreaInset.bottom to the height of the keyboard (346.0 points). Is there any way to access the safeAreaInset.bottom value (34.0) when the keyboard is open? For reference, my content view has a geometry reader in it: var body: some View { GeometryReader { proxy in //I pass in proxy into views in here and then access the safe area with proxy.safeAreaInsets.bottom } } I also need this

How we can read and write to same ObservableObject in SwiftUI?

半腔热情 提交于 2021-02-10 18:40:04
问题 I am making a ObservableObject class and then I am using it for reading and writing value in all app. when I am using my ObservableObject in my StateObject and ObservedObject, they are not the same data, but they are making a different variable in memory, how we can make StateObject and ObservedObject working on a same data? For example my ObservableObject class has a variable called stringOfText , which as default has No Data! then I make a StateObject variable and start reading default

SwiftUI Multiline Text Background Color

天大地大妈咪最大 提交于 2021-02-10 18:27:43
问题 I have a Text view in SwiftUI that will have multiple lines. I know I can change the background color of my text with Text("<long text>").background(Color.red) However if my text is multiple lines the background color will be for the entire frame of the Text view, not just the parts where there is actual text. Like this: I want only the actual text to have the background color. Is this possible? 回答1: It seems SwiftUI doesn't support that yet (Xcode 11.3). You can create a UIViewRepresentable

Reset main content view - Swift UI

霸气de小男生 提交于 2021-02-10 18:20:50
问题 My app has one main screen that the user uses, then once they're done go to another view, currently implemented as a .fullscreencover . I want the user to be able to press a button and the app pretty much resets, turning everything back to the way it is when the app is launched for the first time and resetting all variables and classes. The one method I have tried is opening the view again on top of the final view, however this doesn't reset it. Here is the code I have tried but doesn't work:

How to change navigationBar background color locally

て烟熏妆下的殇ゞ 提交于 2021-02-10 18:18:12
问题 I tried this method but it is global which is undesired. struct ExperienceView: View { init() { UINavigationBar.appearance().barTintColor = #colorLiteral(red: 0.1764705882, green: 0.2196078431, blue: 0.3098039216, alpha: 1) UINavigationBar.appearance().isTranslucent = false UINavigationBar.appearance().shadowImage = UIImage() } } And I tried this method but it is not working, I don't know why. I even tried copying original code on SwiftUI update navigation bar title color, still not working.

Why does Core Data context object have to be passed via environment variable?

穿精又带淫゛_ 提交于 2021-02-10 18:10:36
问题 Inside SceneDelegate the context is passed via .environment(\.managedObjectContext, context) why cannot it be passed via View's property? What's the advantage of doing so? So instead of doing below let contentView = FlightsEnrouteView() .environment(\.managedObjectContext, context) We can pass the context via the View's initializer let contentView = FlightsEnrouteView(context: context) so inside FlightsEnrouteView should be, struct FlightsEnrouteView: View { var context:

Unable to get the response from URL using combine with SwiftUI

家住魔仙堡 提交于 2021-02-10 17:56:15
问题 Thats my model class struct LoginResponse: Codable { let main: LoginModel } struct LoginModel: Codable { let success: Bool? let token: String? let message: String? static var placeholder: LoginModel { return LoginModel(success: nil, token: nil, message: nil) } } Thats my service. I have one more issue i am using two map here but when try to remove map.data getting error in dataTaskPublisher. error mention below Instance method 'decode(type:decoder:)' requires the types 'URLSession

Animated view floats into place weirdly SwiftUI

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-10 16:21:05
问题 So I have a circular progress bar that is declared like this struct ProgressBar: View { var progress: CGFloat var body: some View { let gradient = LinearGradient(...) ZStack { Circle() .stroke(lineWidth: 25) .opacity(0.3) .foregroundColor(Color.secondary) Circle() .trim(from: 0.0, to: CGFloat(min(self.progress, 1.0))) .stroke(gradient ,style: StrokeStyle(lineWidth: 25.0, lineCap: .round, lineJoin: .round)) .rotationEffect(Angle(degrees: 270.0)) .animation(.linear) } } } The variable progress