I added UIButtons to my app and made custom images for them, but when I run the app in the simulator, my buttons are severely stretched - iphone

This is what the storyboard looks like in Xcode
This is what it looks like in the simulator
Does anyone have any idea why this may be happening?

Check that the autolayout constraints for each button are setup properly. i.e. your top left button should probably have a constraint for its width and height and should pin its leading and top space to its superview.

Try resizing your images to the frame size of your UIButton and generate an #2x copy for your retina display. You can also try setting the mode to aspect fit in the attribute inspector.

I deleted the buttons and re-added them, and now it's working well. Thanks for the insights.

Related

Layout for an ios app

I have some issues when i launch my swift application on ipad simulator. I have a home view witch displays 5 images. In my storyboard i have set for all of those constraints for height, width and also spacing. The problem is that when my app is running from ipad , the photo on the middle is situated over the other ones and the spacing is not as i expected.
What i want is a way i can make the same space value between images for each screen size and that the images will resize themselves in order to respect the initial view. Any piece of advice is more than welcome !^.^
Remove width and height constraints for your image views and add equal width and equal height constraints to them. Check out "Auto Layout Tutorial" section "Fixing the width" to see how to set equal width between views. I recommend you to read it whole :)
Nikita is right.
I can add: often apps evolve, so you will add another image.. far better to pass to a CollectionView where every CollectionViewCell owns an image.
In this way:
1) you can decide layout very precisely (with constraints in InterfaceBuilder, or form code using NSCollectionViewFlowLayout delegate methods..)
2) You can manage rotation easily
3) You can scale for iPhone..

UIImageView does not fit my screen properly

I have a UIImageView that fills up the majority of my screen, with the exception of a navigationBar at the top. On my storyboard, I am using the formatting mode titled "compact width|regular height" that is supposed to work for all iPhones in portrait mode. When I attempt to run my app on an iPhone 5c, with iOS8, the imageView does not fill to fit the screen, and appears to "spill out" of the screen, based on the size and positioning of the image within the imageView. I do not have any auto-layout constraints on my imageView, because when I attempt to put them on they enlarge and distort the image even further. I have tried Scale to Fill, Aspect Fill, and Aspect Fit, and none of those work. I have also made sure that the clip to subviews selection button has been checked, so that the bounds are clipped. If anyone can help me, I would really appreciate it. Thanks!
You can disable the auto-layout and use the autoresizing mask.
I used this on images and fixed the prob like yours that I had.

Xcode not respecting the constraints on my iphone xib file

I am having problems figuring out why Xcode is not respecting the constraints on my iphone xib file.
This is how I set a button in the xib file:
and this is how it appears in the simulator:
and this is how it appears in the simulator:
I defined the size of the button:
Any of you know what I'm doing wrong?
I'll really appreciate your help.
If you want the button to stay at the center of the view, you just need two constraints.
vertically center in container
horizontally center in container
Add this two and get rid of the vertical space containers.
Don`t no much about constraint but u can remove it with Doing uncheck in AutoLayout in property editor.
And than palce your button and make it center horizontal and center vertical from property editor of xib.
And make all bounds pack in AutoSizing given in property editor.

Why do my UIImageviews get resized/dimmed when using UINavigation/UITabbar controller

I have an app with a primary view that has a UITabBarController with 5 tabs. Each tab is a UINavigationController.
In interface builder, I'm customizing the background of each page by dragging a UIImageView and setting it fullscreen. The image I'm setting to the view is 640x960. I am setting it to be Aspect Fill.
However, what I've noticed is that it is not where I would expect it to be. When navigating between by tabs, the image seems to be shifted down from where it should be.
Also, when pushing a new view to the navigation controller, the background of this new view isn't offset in the same way as the tabbar one, and it is also slightly dimmed.
How can I set my UIImageViews on each page to be aspect correct and fill the screen 1:1? Also, how does one disable the dimming when pushing a view to the navigation controller?
Thanks for any tips, and apologies if this is covered in another thread, I couldn't find an answer searching the site.
Assuming that you are using the IB to setup your views, you should select navbar/tabbar options to reflect what will be on the actual page. That should place your image correctly. I would also recommend that you make both a low res and hi res version of your background images -- 320x480 and 640x960. Of course, your size may need to be adjusted (reduced) for the navbar and/or tabbar which will leave less than 960 px of vertical height -- probably more like 920px if you are in portrait mode. Then you add #2x to the base name of the hi res version, this would account for older iPhone screens.
Once you have the image placed correctly, resizing should be unnecessary. You can have the image automatically resize width and height using the little arrows on the layout page -- that's a bit hard to describe. It can also be done in code -- if you still need that I can provide a sample.
Maybe you need to set all AutoresizingMask in order to resize the UIImageView properly on each view. And to main aspect ratio u should use either AspectFill or AspectFit on the contentMode.

tranisition from iphone to ipad nibs

i am wondering how its possible to have an iphone nib that has some uitextfields and some labels to be automatically repotitioned if the device is an ipad. (i dont want a second nib) im trying to get my iphone nib to autoresize in the middle of the screen if the device is an ipad so that all the text fields and buttons arent placed in the top left corner. I tired using the autosizing masks however they wouldnt work for the textfield(im not sure why exactly the horizontal autoresize didnt work) is there any way i can do this without making a new nib if the device is an ipad?
thanks
I'm unsure if this would work, but you might try using a view that's the same size as the iPhone screen, set the autosize flags on that to keep it in the middle of the screen without stretching it, then put all of your views inside that view.