user2695433 user2695433 - 7 months ago 23
Swift Question

ImageView width not scaled to fill ParentView in Autolayout iOS

I have tried to fill the

UIImageView
to fill the Image to be shown like a Top Header (logo). But it appears to have a 20px gap at the leading and trailing end.

I have used Leading and trailing constraints
0
but it shows 20 px gap (padding). If I'm using
-20
for leading and trailing contraints then it works well but the image seems to be stretched.

What should I do to overcome this weird issue?

I have even tried using Equal width contraints with Imageview and Parent View controller View, but still with no success.

dzk dzk
Answer

Remove the current leading and trailing constraints. Add them again, but uncheck the Constrain to margins option, and now enter 0 for both leading and trailing constraints.

That should fix it.