swiftui

SwiftUI: How to connect currentPage of PageView with firing view's passing index

邮差的信 提交于 2021-02-11 12:11:16
问题 I follow Apple's example interfacing-with-uikit to use PageView in SwiftUI. And I want to implement it in my app. The scenario is that in MovieView , when the user taps an image of image list then it triggers call to PageView with views and selected index as parameters. But when I click on any item of image list, it always show the page view with the 1st element. I try to change it in init() of PageView , however it is not working. In console, I try to print something, and I see the

SwiftUI/UIKit How to convert SwiftUI Font to UIKit UIFont?

半腔热情 提交于 2021-02-11 11:09:03
问题 Due to some limitations in SwiftUI Text. I've to use the UIText instead. In an UIViewRepresentable, func makeUIView(context: Context) -> UITextView { let vw = UITextView() let env = context.environment // UIFont? Font? vw.font = env.font ... } I want to initialize the UIKit UILabel using the SwiftUI EnvironmentValues. More specifically, assign an SwiftUI Font to UIKit UIFont. The question is, how to convert a Font to UIFont? 回答1: If you need share same font, then use UIFont as model property

SwiftUI/UIKit How to convert SwiftUI Font to UIKit UIFont?

我只是一个虾纸丫 提交于 2021-02-11 11:03:40
问题 Due to some limitations in SwiftUI Text. I've to use the UIText instead. In an UIViewRepresentable, func makeUIView(context: Context) -> UITextView { let vw = UITextView() let env = context.environment // UIFont? Font? vw.font = env.font ... } I want to initialize the UIKit UILabel using the SwiftUI EnvironmentValues. More specifically, assign an SwiftUI Font to UIKit UIFont. The question is, how to convert a Font to UIFont? 回答1: If you need share same font, then use UIFont as model property

SwiftUI/UIKit How to convert SwiftUI Font to UIKit UIFont?

只愿长相守 提交于 2021-02-11 11:01:53
问题 Due to some limitations in SwiftUI Text. I've to use the UIText instead. In an UIViewRepresentable, func makeUIView(context: Context) -> UITextView { let vw = UITextView() let env = context.environment // UIFont? Font? vw.font = env.font ... } I want to initialize the UIKit UILabel using the SwiftUI EnvironmentValues. More specifically, assign an SwiftUI Font to UIKit UIFont. The question is, how to convert a Font to UIFont? 回答1: If you need share same font, then use UIFont as model property

SwiftUI/UIKit How to convert SwiftUI Font to UIKit UIFont?

 ̄綄美尐妖づ 提交于 2021-02-11 11:01:37
问题 Due to some limitations in SwiftUI Text. I've to use the UIText instead. In an UIViewRepresentable, func makeUIView(context: Context) -> UITextView { let vw = UITextView() let env = context.environment // UIFont? Font? vw.font = env.font ... } I want to initialize the UIKit UILabel using the SwiftUI EnvironmentValues. More specifically, assign an SwiftUI Font to UIKit UIFont. The question is, how to convert a Font to UIFont? 回答1: If you need share same font, then use UIFont as model property

SwiftuUI NavigationLink inside touchBar

情到浓时终转凉″ 提交于 2021-02-11 08:55:14
问题 I'm trying to create NavigationLink in MacBook touchBar with help of SwiftUI. Actually with my piece of code, the button is shown in touchbar, but unfortunately the link doesn't work. NavigationView { .touchBar { NavigationLink(destination: BookView()) { Text("GoToBook") } } } struct BookView: View { var body: some View { Text("Hello") } } 回答1: Try instead with Button in touchBar activating NavigationLink programmatically, like below @State private var isActive = false ... // below in body

Swiftui timer not firing after navigating back

大兔子大兔子 提交于 2021-02-11 07:02:39
问题 i have a timer in SwiftUI which works when opening the view for the first time. When navigating back and opening again, the timer does not start. Any idea what can be wrong ? import SwiftUI struct ClockDetail: View { @State var seconds: Int = 0 @ObservedObject var motion: MotionManager let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() var body: some View { VStack(alignment: .leading) { Text("\(seconds)").font(.title).onReceive(timer) { output in self.seconds += 1 }

SwiftUI - Why does the keyboard pushes my view?

天大地大妈咪最大 提交于 2021-02-11 06:35:29
问题 Why do I have the keyboard that pushes up my View? Here's the code: import SwiftUI struct ContentView : View { @State var searchText = "" @State var pressedFirstButton = false @State var pressedSecondButton = true @State var pressedThirdButton = false var body : some View { NavigationView { VStack { if pressedSecondButton == true { Form { SearchBar(testo: $searchText) .padding(.horizontal, -10) Text("ForEach") } } HStack { Spacer() buttonFirst Spacer() buttonSecond Spacer() buttonThird Spacer

SwiftUI - Why does the keyboard pushes my view?

蹲街弑〆低调 提交于 2021-02-11 06:35:07
问题 Why do I have the keyboard that pushes up my View? Here's the code: import SwiftUI struct ContentView : View { @State var searchText = "" @State var pressedFirstButton = false @State var pressedSecondButton = true @State var pressedThirdButton = false var body : some View { NavigationView { VStack { if pressedSecondButton == true { Form { SearchBar(testo: $searchText) .padding(.horizontal, -10) Text("ForEach") } } HStack { Spacer() buttonFirst Spacer() buttonSecond Spacer() buttonThird Spacer

SwiftUI: How to constrain image size?

南笙酒味 提交于 2021-02-11 06:16:26
问题 I am trying to constrain image size between min and max. But the view expands both width and height to their max values, removing the original aspect ratio. import SwiftUI struct ImageConstrainSizeTest: View { var body: some View { Image("bike") .resizable() .aspectRatio(contentMode: .fit) .border(Color.yellow, width: 5) .frame(minWidth: 10, maxWidth: 300, minHeight: 10, maxHeight: 300, alignment: .center) .border(Color.red, width: 5) } } struct ImageConstrainSizeTest_Previews: