ios - Automatically set height of custom UIView based on its contents? -


i’ve taken lot of time read other questions before asking one, , haven’t managed solve issue yet – can help.

i have custom alert view, uiview subclass. i’m trying state width fixed, , height grows dynamically based on height of 2 labels (title , message), , dynamic number of action buttons can set with.

i’ve used autolayout set controls, working fine, i’m still manually setting frame of view in initialiser.

what need have view’s height calculated height of 2 labels, , n buttons, plus spacing between them.

i’ve tried providing intrinsiccontentsize view, method never called, , doesn’t ask it, i’m stumped how proceed.

to summarise: need ios9’s uistackview, don’t have luxury, need bake similar ios 7 / 8. i’ve looked @ oastackview i’d rather not use external dependency.

just quick thought: have tried create view in interface builder? give fixed width priority: 1000. add no height constraint center view vertically in superview.

then set view's vertical content hugging priority , vertical content compression resistance priority 1000.

this should cause view calculate own height based on subviews. need make sure, subviews bound superview in way defines height without ambiguity.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -