Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting frame or bounds of UIView within UIViewRepresentable

Tags:

ios

swift

swiftui

In my ContentView I have a simple custom view:

var body: some View {
    VStack {
        Text("Hi")
        Circles().frame(width: 200, height: 200)
        Text("Bye")
    }
}

where Circles is a UIViewRepresentable:

func makeUIView(context: Context) -> CircleView  {
    return CircleView()
}

CircleView is A UIView but I'm unable to find get frame or bounds where the height and width are non-zero. The view displays at the correct size, but I can't where in the UIView life cycle that layout has completed. (At init time the height/width are still 0)

like image 953
Martin Avatar asked Oct 23 '19 05:10

Martin


1 Answers

At least in UIView.layoutSubviews the bounds is already valid (I used override it for the needs of layouting sublayers).

open func layoutSubviews()

You can override other UIView methods to find out where it becomes defined for your needs.

like image 53
Asperi Avatar answered Nov 01 '22 08:11

Asperi