UIButton height is 0 but title is still visible UIButton height is 0 but title is still visible ios ios

UIButton height is 0 but title is still visible


You can check Clip Subviews on interface builder or if you want do it by code try this:

myButton.clipsToBounds = YES

from apple documentation:

clipsToBounds

A Boolean value that determines whether subviews are confined to the bounds of the view.

@property(nonatomic) BOOL clipsToBounds

Discussion

Setting this value to YES causes subviews to be clipped to the bounds of the receiver. If set to NO, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value is NO.


Maybe you should call

[button.layer setMasksToBounds:true];

and then layoutIfNeeded.

Obs.: probably requires the Quartz framework.


The title is always visible regardless of the button heigth, it is a UILabel with it's own size setting. Why do you want to have a button with height 0 anyway? If you want to hide a button simply set the Hidden property of your button to true;

[button setHidden:TRUE];


matomo