Ali Alzahrani
Ali Alzahrani

Reputation: 529

UIbutton stretching after runtime

I have form page with few textfields and a button. I have added constraints for each component as well.

The issue is that the button getting stretched after running the app. Please see below screenshots for my issue.

1- button size in storyboard button size in storyboard

2- constraints

enter image description here

3- result in simulator

enter image description here

Upvotes: 0

Views: 38

Answers (2)

Tharindu Ketipearachchi
Tharindu Ketipearachchi

Reputation: 1066

This is happening because the height of the device you running is larger than the device you have selected on your storyboard. To overcome this issue.

  • You can give a fixed height for the UIButton and remove the bottom layout constraint(lazy fix).
  • The better and easiest way is to use vertical UIStackView and give proportional heights to all the components. Read this article to gain more knowledge about UIStack views.

Upvotes: 3

Shehata Gamal
Shehata Gamal

Reputation: 100503

The height of the device you implement your constraints in is smaller than the device you test in , since you have leading , trailing , top and bottom your button will stretch depending on current device , so either remove the top/bottom constraint according to your design need

You can optionally add height to the button or leave it with it's intrinsic size

Upvotes: 0

Related Questions