Reputation: 13
I'm simply trying to fill the entire width of an iPhone screen with a login button for my users that is basically an image set as the background of a UIButton
. This is the result I end up with (Notice it fills width as intended, but shrunken down in height):
My thought process was to make 3 images to compensate for @1x
@2x
@3x
resolutions with different image sizes?
@1x: 144x33px
@2x: 288x65
@3x: 432x97
Now from there I thought I could just fill the width of my ViewController
with the UIButton in Storyboard and set the background image of the UIButton
which I would think would use the proper one automatically depending on device considering I put them in the right spots in Images.xcassets
. I also set the trailing and leading constraints as well as bottom constraint to keep it filling left to right and stick to bottom. I just don't get how I would fix the height issue if it's looking fine in the actual XCode storyboard, but not in the preview or simulator as seen in above photo.
Any help would be tremendously appreciated.
Upvotes: 0
Views: 1178
Reputation: 406
The different image sizes are not used to replace each other when you scale an image. They are used to look nice when there are more actual pixels than software pixels.
For your purposes, you probably want to scale the image with the stretching rules or cap insets.
Check out this answer for an example:
https://stackoverflow.com/a/13367861/1864591
Upvotes: 1