uikit

How to mask a UIStackView in Swift?

孤者浪人 提交于 2020-07-20 03:41:50
问题 I understand that UIStackViews are not rendered the same way the rest of view components are and thus they cannot be masked. Nonetheless I am sure there are work arounds. Is there any way to mask a UIStackView? Specifically a stack view that has other UIStackViews as subviews. 回答1: You can't, I believe. Although it's a subclass of UIView , you still can't even set a backgroundColor to it. Apple says: The UIStackView is a nonrendering subclass of UIView; that is, it does not provide any user

SwiftUI: UIAlertController's textField does not responding in UIAlertAction

人盡茶涼 提交于 2020-07-03 11:41:11
问题 I need to use UIAlertContoller , as SwiftUI's Alert does not support TextField . I must not use Custom created AlertView, due to various reason(Accessibility, DynamicType, Dark Mode support etc). Basic Idea is, SwiftUI's alert must hold TextField & entered text must be reflect back for usage. I created a SwiftUI view by Conforming to UIViewControllerRepresentable following is working code. struct AlertControl: UIViewControllerRepresentable { typealias UIViewControllerType = UIAlertController

SwiftUI: UIAlertController's textField does not responding in UIAlertAction

北城余情 提交于 2020-07-03 11:40:03
问题 I need to use UIAlertContoller , as SwiftUI's Alert does not support TextField . I must not use Custom created AlertView, due to various reason(Accessibility, DynamicType, Dark Mode support etc). Basic Idea is, SwiftUI's alert must hold TextField & entered text must be reflect back for usage. I created a SwiftUI view by Conforming to UIViewControllerRepresentable following is working code. struct AlertControl: UIViewControllerRepresentable { typealias UIViewControllerType = UIAlertController

How to make a UIViewRepresentable @ViewBuilder work with dynamic content?

梦想与她 提交于 2020-06-29 06:43:13
问题 Is it possible to make a UIViewRepresentable view which takes a ViewBuilder argument work with dynamic content such as ForEach loops? I have the following UIViewRepresentable view which I’m using to drop down to UIKit and get some custom UIScrollView behaviour: struct CustomScrollView<Content:View>: UIViewRepresentable { private let content: UIView private let scrollView = CustomUIScrollView() init(@ViewBuilder content: () -> Content) { self.content = UIHostingController(rootView: content())

How can I use a UIBezierPath to create a curved line chart with data points?

本小妞迷上赌 提交于 2020-06-28 05:16:32
问题 I am trying to use a UIBezierPath to create a line chart. My goal is to animate this chart and have it appear to be "wavy." But I can't seem to get the path to mirror my data. Edit: Added Data Points let dataPoints: [Double] func wave(at elapsed: Double) -> UIBezierPath { let amplitude = CGFloat(50) - abs(fmod(CGFloat(elapsed/2), 3) - 1.5) * 100 func f(_ x: Int) -> CGFloat { return sin(((CGFloat(dataPoints[x]*100) / bounds.width) + CGFloat(elapsed/2)) * 4 * .pi) * amplitude + bounds.midY }

How to use an NSAttributedString with a ScrollView in SwiftUI?

北城余情 提交于 2020-06-27 18:31:34
问题 I've been able to render NSAttributedString s via UIViewRepresentable which works great until I wrap the view in a ScrollView . When placed inside the ScrollView , the NSAttributedString view stops rendering. I've tried some other methods that replace an NSAttributedString with adding multiple Text() views together to get formatting which works inside the ScrollView and supports italics and monospace font . Unfortunately this doesn't work for links inside text blocks, which means I still need

iOS Keyboard Colour Changes - keyboardAppearance dark color doesn't stick

浪子不回头ぞ 提交于 2020-06-27 07:31:14
问题 In our app, we set the keyboardAppearance to dark. This produces a black keyboard, as expected. However, if the keyboard is showing, and we press the home button, and then go back into the app, the keyboard turns white, as shown. Any ideas why? 回答1: It may have todo with the fact that the keyboard is a global object. There's only ever one keyboard in memory at any given time. Also, the OS will automatically change the keyboard color based on the background. Therefore, your setting is probably

How do I present a view controller over current context with a custom transition?

不羁的心 提交于 2020-06-24 08:29:22
问题 I am running into a problem with view controller containment and wanting to present view controllers "over current context" with a custom presentation/animation. I have a root view controller that has two child view controllers that can be added and removed as children to the root. When these child view controllers present a view controller I want the presentation to be over current context so that when the child that is presenting is removed from the view heirarchy and deallocated the

Save dictionary to UserDefaults

戏子无情 提交于 2020-06-22 17:58:49
问题 I'm trying to store a dictionary in UserDefaults and always get app crash when the code runs. Here is the sample code which crashes the app when it is executed. I tried to cast it as NSDictionary or make it NSDictionary initially - got the same result. class CourseVC: UIViewController { let test = [1:"me"] override func viewDidLoad() { super.viewDidLoad() defaults.set(test, forKey: "dict1") } } 回答1: Dictionaries are Codable objects by default, you can use the following extensions to save them

How to find the frame of a swiftui uiviewrepresentable

前提是你 提交于 2020-06-16 07:44:06
问题 I'm trying to wrap a custom subclass of UILabel in UIViewRepresentable to use it in Swiftui. I'm using .sizeToFit and printing the frame, and it looks right while it's in the wrapper: func makeUIView(context: Context) -> CustomUILabel { let view = CustomUILabel() view.customProperty = model.customProperty view.sizeToFit() print(model.latex,view.frame.size) // this prints the correct size, how to propagate? return view } but when I run this in a Vstack, it draws the UIViewRepresentable with