How to autosize view without auto layout in iOS - ios5

I have a problem that I can't understand resizing views. My deployment target is iOS 5.0, so I have disabled auto layout in the interface builder to make it compatible with iOS 5.0. The view does not resize automatically. Following is an example:
Interface Builder Snapshot:
4-inch screen:
3.5-inch screen (has problem):
As you can see, the button at the bottom of the view goes out of the screen. The background image also does not resize automatically. I can not understand how I can solve this problem. Can anyone help me?

Welcome to the pre-autolayout world! You must set the autoresizing "springs and struts" so that the stuff at the bottom is attached to the bottom of the superview and not the top. So, struts to the bottom, springs to the top. That way, as the superview gets larger and smaller, the stuff at the bottom moves with the bottom.
You could alternatively reposition the stuff in code, but there's no need in this situation.
Here's the section on autoresizing from my book:
http://www.apeth.com/iOSBook/ch14.html#_autoresizing
The part about the superview and the background image not being resized is a different matter. Is this the view of a UIViewController? If so, then if you are putting the UIViewController into the view controller parent-child hierarchy correctly, it will be resized by its parent. But you have not shown any code, so there's no telling what this view may be or how it is supposed to get into the interface.

Related

How to get the visible view size in iOS13 when presenting a view controller

In iOS13, the default way when presenting a view controller was changed to the "sheets/cards" view. As I’m not using auto layout (why not, is not really important and relevant), I rely on getting position of elements based on the frame of the view.
Now, the problem with the new method is, that the view frame doesn’t really reflect the actual content size visible on the screen anymore. E.g. if I have positioned a UIButton at the bottom on the view controller based on the view.frame bottom coordinate, it will be now cut off, as the view is actually moved down in the amount of the nice "sheets/cards" visual indication at the top. The same problem is even more evident in an iPad, where centring another view in the view controllers view will be offset, due to the fact that the default presentation style is now a "sheet" in the middle of the screen.
I’ve currently changed everything to force the full screen version, but it would be nice to use the new fancy design.
Anybody has any idea how to get the actual visible rect/coordinates in the new style without changing things to auto layout?
Here are how they look. The "flower" is centered in the view and the X button should not be so close to the bottom or missing completely in the iPad version.
Finally figured it out. As I was setting the positions of items in viewDidLoad, the frame was not calculated correctly, thus resulting things being laid out incorrectly. When resetting the frame and positions in viewDidLoadSubviews, the positions were placed correctly.

swift programming - storyboard how to add more buttons on a viewcontroller

Hi I'm new to iphone programming and I'm having problem with scrolling on the storyboard. Let's say I need to add 30 buttons on a viewcontroller inside a scrollview, but the screen size only fits 15, how do I scroll down and add more buttons.
screen shot 1
Another problem I have is that when I run the iphone app on the simulator, it can only scroll down too the button 13 even though there are 15 buttons on my view controller.
screen shot 2
Thanks for your help.
you can scroll the scrollView on the storyboard. Scroll down and then add buttons.
You need to set a size appropriate for Scroll ContentSize. Take a note at that.
Please do provide more info from. Its gonna make the resolution process easy.
Take a look at this link for solid ScrollView intro:
http://www.raywenderlich.com/76436/use-uiscrollview-scroll-zoom-content-swift
In the storyboard... Just make the view bigger. In your case, you want to change the height:
For the problem of not being able to scroll across all your images. You need to make sure the scroll view is pinned to all four sides of the parent view and that the height and width are all set-up for the content inside the scroll view. (make sure there are no warnings associated with the scroll view in the storyboard.)

UISegmentedControl inside UIToolbar does have wrong height for Lanfscape

Somehow the Segmented Control does not get the proper height when the iPhone is in Landscape.
It is already bad enough when rotating the simulator that the toolbar at the bottom doesn't get thinner height, but when navigating back to the previous screen and then in again, the toolbar does get the propper height, but the segmented control extends above it, and even looks much bigger.
Is the is bug in the simulator or am i doing something wrong?
After digging around another day, I found where it all went wrong!
When dealing with UINavigationControllers, DO NOT drag in a UIToolbar at all! UINavigationController comes with two bars, a top-bar for the Navigation Controller and a bottom-bar for the ToolBar - that latter one is hidden by default.
In any newly added ViewControllers, there will be a toolbar that can be populated from the IB. However, if it is not a UIBarButton, there are some issues. To use a stepper, on/off-switch or a segmented control, drag it first to the Navigation bar, and then in the left column navigator of IB, drag it to the toolbar.
This solved all the problems mentioned before

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.

Iphone View Rotation not functioning properly

I have a simple 1 screen app, with 1 View.. the view contains
a button, an textbox and a button across the top
A segmented controller across the bottom
and a MapView in between.
In portrait mode all is right with the world.. So I decided to begin to allow Orientation change...
in IB all views and elements and even the root window have autoResizeSubviews set
in My AppDelegate and my viewController I have also programatically added SetAutoResizeSubviews to yes explicitely I have set the autoResizingMask in the Root Window and the View Controller to FlexibleWidht | Flexibile Height
I have added the shouldAutorotateToInterfaceOrientation in my ViewController to always return true.
Yet, it doesn't work.. Or should I say it doesn't rotate properly.. in both portrait modes everything looks great, but both landscape modes, things don't get laid out or resized properly.. Basically all I see is the mapview, and its size gets slightly wider, but not much than the portrait mode, and it doesn't fill up the screen top to bottom.. all other interface elements with the exception of one button are invisible and it appears on TOP of the mapview.. as thought it just happened to be layed out over the view by coincidence than any design.
Anyone have any ideas what I am missing, or why?
Thanks in advance
You say "I have set the autoResizingMask in the Root Window and the View Controller" but that is a red herring. It is the buttons, the text box, the segmented controller, and the map view that have to have the correct autoresizingMask. If this view is being designed in the nib, you can set the values there and then turn the orientation right there in the nib and see what happens.
If you are unable to work out good autoresizingMask values for all those interface elements, implement didRotateFromInterfaceOrientation and perform the layout alterations in code when called upon to do so.