thecloud_of_unknowing
thecloud_of_unknowing

Reputation: 1205

How to determine the readable content width of a view?

I need to determine what the width of the readable content of a view is. Obviously I could add a subview to the view in question, set its width to be equal to the readable content width of its super view, and then measure the subviews width. But that feels hacky. I would like to know the readable content width before adding said constraints as I need to perform logic based on this value. Is there a way to do this other than the hack I have suggested?

Upvotes: 2

Views: 294

Answers (1)

Alladinian
Alladinian

Reputation: 35616

You can inspect the (readable) layout frame via view.readableContentGuide.layoutFrame (and thus the width as in any CGRect)

Please note that:

This property contains a valid CGRect value by the time its owning view’s layoutSubviews() method is called.

Upvotes: 3

Related Questions