Questions tagged [uiviewrepresentable]
229 questions
36
votes
1 answer
SwiftUI - State change in UITextField causes the frameWidth to grow uncontrolled and ignore bounds/frame
I am using SwiftUI and bridge to UITextField (I need to assign firstResponder). I use the code from here: SwiftUI: How to make TextField become first responder?
The following code updates my @Binding var. This of course is intended behavior. The…

denninho
- 473
- 4
- 7
17
votes
2 answers
SwiftUI View not updating its state when embedded in UIView (using UIHostingController)
I'm wanting to use a SwiftUI View as content for a child UIView (which in my app would be inside UIViewController) by passing SwiftUI. However the SwiftUI View doesn't respond to state changes once embedded inside UIView.
I created the simplified…

Damo
- 171
- 1
- 3
15
votes
3 answers
SKView warning logs
When running my SwiftUI & SpriteKit app, I get the following messages in the logs:
2019-11-18 21:58:57.631912+0000 PixelBattles[2812:1215803]
SKView: ignoreRenderSyncInLayoutSubviews is NO. Call _renderSynchronouslyForTime without handler
What am…

George
- 25,988
- 10
- 79
- 133
13
votes
4 answers
Size a UILabel in SwiftUI via UIViewRepresentable like Text to wrap multiple lines
The goal is to get a UILabel integrated via UIViewRepresentable to size the same way Text does - use the available width and wrap to multiple lines to fit all the text thus increasing the height of the HStack it's in, instead of expanding in width…

Jordan H
- 52,571
- 37
- 201
- 351
13
votes
4 answers
Implementing Apple Pay with SwiftUI
This is my first time working with PassKit and with SwiftUI on a big project. I'm trying to implement Apple Pay SwiftUI and since there isn't a native way to do so yet, I tried wrapped the PKPaymentAuthorizationViewController in…

user2805119
- 223
- 3
- 6
9
votes
6 answers
SwiftUI - iOS 13 UIViewRepresentable of WKWebView gets Thread 1: EXC_BREAKPOINT crash
I'm trying to port WKWebView over to SwiftUI. Here's my code:
import SwiftUI
import WebKit
struct ContentView: View {
var body: some View {
WebViewWrapper()
}
}
/**
WKWebView ported over to SwiftUI with `UIViewRepresentable`.
…

aheze
- 24,434
- 8
- 68
- 125
9
votes
2 answers
Set custom UIView frame in UIViewRepresentable SwiftUI
I'm trying to use my custom UIView in SwiftUI using UIViewRepresentable and I want my UIView to have the same size as I set in .frame() so that I can use it like this:
MyViewRepresentable()
.frame(width: 400, height: 250, alignment: .center)
For…

IrelDev
- 317
- 5
- 12
9
votes
4 answers
Changes to ObservedObject don't update a UIViewRepresentable
Simplest example below. Works fine in preview (UITextView text updates to "ouch"). But, run it in an app (ie add as rootView by the sceneDelegate), and the UITextView doesn't update.
import SwiftUI
class ModelObject : ObservableObject{
…

Rumbles
- 806
- 1
- 8
- 15
8
votes
2 answers
How to render multiline text in SwiftUI List with correct height?
I would like to have a SwiftUI view that shows many lines of text, with the following requirements:
Works on both macOS and iOS.
Shows a large number of strings (each string is backed by a separate model object).
I can do arbitrary styling to the…

Jaanus
- 17,688
- 15
- 65
- 110
8
votes
1 answer
SwiftUI not refresh my custom UIView with UIViewRepresentable & ObservableObject
I have
created a simple ARClass: ObservableObject with @Published var name: String
created a custom ARView: UIView that receives ARClass as a
parameter and draws a Text view displaying ARClass.name in the center
created UIViewRepresentable
and…

Anan R
- 311
- 4
- 8
6
votes
0 answers
How to programmatically trigger UIMenu from UIViewRepresentable
I tried to create a custom SwiftUI menu (based on UIMenu).
However, I'm unable to trigger the primary action.
It works when I tap on the CustomMenu but the programmatic action is not triggered. What am I doing wrong?
struct CustomMenu:…

pawello2222
- 46,897
- 22
- 145
- 209
6
votes
1 answer
How to use PKToolPicker with PKCanvasView in SwiftUI
Currently, I am able to have a separate PKCanvasView and a PKToolPicker that is shown when a button is tapped on. However, the tool is not being transferred between the picker and the canvas view. Does anyone have any idea how to link the two such…

HeySaiK
- 480
- 1
- 6
- 17
6
votes
0 answers
How to get dynamic height for UITextView in SwiftUI
I'm getting really close to implementing dynamic height for a UITextView in SwiftUI. Please help me work out these kinks:
The UITextView has the correct height when it appears but does not adjust height as editing is being performed; I would like…

atdonsm
- 265
- 4
- 11
6
votes
1 answer
Apply ViewModifier to UIViewRepresentable
I created a UIViewRespresentable for a UITextField. I'd like to apply modifiers:
myTextField.font(.headline).keyboardType(keyboardType)
This is not working, even if my UIViewRepresentable is simple:
class MyTextField: UITextField { ... }
struct…

P. Ent
- 1,654
- 1
- 12
- 22
5
votes
1 answer
UIImageView Representable not resizing
I can't find a way to make a UIImageView wrapped in a UIViewRepresentable be sized to fit the frame. It always resizes beyond the screen no matter what content Mode or clipping or explcit framing I do. (The image dimensions are much larger than the…

santi.gs
- 514
- 3
- 15