kukudas kukudas - 6 months ago 89
iOS Question

Hide UILabel without consuming any space

I know of two ways hiding a

UILabel
. I can either set the alpha to 0 or the labels property 'hidden' to YES. That is

// UILabel *label = ...
label.alpha = 0.0f;

// or
label.hidden = YES;


However in both cases the label will take space (its width and height).

Is it possible to hide a label so it wont take any vertical/horizontal space? One possible way would be to set the width/height to 0 i guess. But maybe there is a better way.

Answer

Well You can set the frame height value to 0 to hide the label.[Using autolayout? this may be enough if you set it properly]

Without autolayout, to move the content below up and it depends on setting the frame of the contents below to new frame programatically [change all components y value to yvalue-label.height]