Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton height is 0 but title is still visible

I have an UIButton placed with constraints. In the interface of the view controller I created an IBOutlet for the height constraint of the button. In viewDidLoad method I have the code:

myButtonConstraint.constat = 0; [self.view layoutIfNeeded]; 

In viewWillAppear the height of the button is 0, but on the simulator the title of the button is still visible. Even though the title of the button is visible, the button is not tappable, it performs no action.

What is going on?

like image 466
Andrei Marcu Avatar asked Mar 17 '14 19:03

Andrei Marcu


1 Answers

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.

like image 97
rafaperez Avatar answered Sep 23 '22 03:09

rafaperez