Adaptive Layout - calculate second row of views based on view width

I am programmatically adding a dynamic number of UIButton which are labeled as hashtags to a compact view using Adaptive Layout. Is there a way for adaptive layout to automatically calculate when the width of the view is met and a new line is needed, or do I need to calculate that myself, then manually anchor the next row of buttons under the previous and so on?

My current source gives me the following image, where a second row is needed. Appreciate any direction on this.


Auto layout cannot do this, so if you want to use individual buttons, you'll have to calculate it yourself. Another alternative would be to use a collection view which will automatically layout the buttons (cells).