Search code examples
iosswiftxcodeuibuttonxcode7

The UIButton works fine at first run, but doesn't work at the second run on the simulator


I have been trying to make this basic app. I added segue to the main view controller. In the segue, I added a button that will play a video on button click. The button works completely fine at the initial run of the simulator, but when I run the app again, after adding constraints, the button disappears and all I can see is text written on the button. Also, I did not even connect the button using IBAction or IBoutlet.

Constraints:

constraints screenshot

With Constraints:

simulator screenshot


Solution

  • If you simply want to keep the button in the center of the screen, use the Alignment Constraints and make both centre vertically and horizontally.

    enter image description here

    In case you want to place it anywhere else, then only adding the leadingConstraint and the topConstraint is more than enough.