0

When creating custom views, I generally create an initialization function by overriding the init(frame) function. When creating the view in my ViewController I initialize the view by passing in the .zero frame, and then set the layout using Material's layout function.

let descView = DescriptionView(frame: .zero)

However, this makes it so that my views in my custom view are not resized. For example, when setting up a custom text view in my custom view, it does not show up because I prepare it as so:

self.layout(descriptionTextView).width(self.width).height(self.height).centerVertically().centerHorizontally()

I assume it doesn't show up because when I initialize the view, its width and height are zero. What can I do to get around this?

7
  • What is the look you are trying to go for? Do you know the width and height you are after? Or are you trying to stretch the view? Commented Oct 6, 2017 at 14:24
  • I initialize the view with a CGRect of .zero and then use view.layout to resize the view how I want it. Commented Oct 8, 2017 at 3:23
  • I understand what you are trying to do, but you are also using values of zero. So you are technically not doing anything incorrectly. It is the values that you are using that are most likely not correct. Commented Oct 8, 2017 at 18:26
  • Hmmm...should I be stretching the view using layout then adding the subviews outside of the class? Commented Oct 9, 2017 at 17:53
  • I need to see what you want to accomplish, I am not fully understanding what you want to do. Commented Oct 10, 2017 at 13:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.