Auto Resizing with Interface Builder and Code? - iphone

I want to use auto resizing mask in iPhone to adjust view in landscape and portrait mode. The problem is when I apply width spring from Interface builder, the button changes its size proportionally. But when I apply the same spring by code i.e.
[self.view setAutoresizesSubviews:YES];
[testButton setAutoresizingMask:UIViewAutoresizingNone];
[testButton setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
the button doesn't show the same behavior.
Auto resizing applied on button from Interface builder:
original button size: 120 width and 37 height
landscape mode button: changes size proportionally
Auto resizing applied on button from Code:
original button size: 120 width and 37 height
landscape mode button: changes size by keeping same left and right margins in both Portrait and landscape mode.
The mask applied from code doesn't seem to work correctly as the size of button created from code comes out to be greater.
My views are complex that is why i don't want to set the frames of each subview on the View.
Anyone with same issue!!!

Thnx for responding guys, by the way I have solved my issue. There was nothing to do with the link with the interface builder. Actually while creating your view without interface builder, if you want the subviews to be auto re-sized; You have to set springs and struts in a single line using the bitwise OR connector. The code I used for re-sizing my view is:
[appLogo setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];

Check 2 things.
1. Connection of IBOutlet
2. Also check that you have created the #property of the IBOutlet of view you have created.
Hope this solve the issue.

Related

Re-size the TabelView in iphone 5

I'm using the Autosizing mask for UITableView so it is working fine with iPhone 5 as well, but I'm doing some frame animation in that controller so the UITableView automatically reduces its height.
Not able to understand What is going wrong. I did the autosizing mask programmatically also but doesn't works. I'm stuck here...!
Lots of thanks.
you should not use UIViewAutoresizingFlexibleBottomMargin in autoresizing mask if there is Tab bar bottom toolbar at bottom of the table.
Try this code..
self.tblRoomList.autoresizesSubviews = YES;
self.tblRoomList.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin;
Or do like this

iphone 5 showing white strip at bottom

My app works fine in iphone 4 but my iphone 5 showing this below white strip. I have added
Default-568h.png too but issue is still there. What should I do?
It looks like you need to set the resizing masks for the view. Make sure it's set to stretch by height in the Autosizing section of the size inspector in Interface builder. Or set the masks appropriately in code if you're not using interface builder.
Edit---
In Code:
see autoResizingMask:
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html
Interface builder:
The Autosizing section is what you want.
Make sure the masks are set like this for the view. You will also want to set the outer bars for any controls. Clicking the bottom bar will tell the button to stick to the bottom of the view for instance.
try this one :
yourView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin ;

Rotating the uiview without IB

In my app all my controls are created in code. I have not used IB for controls. now i want to rotate the view to landscape mode. I know I have to use the shouldAutorotate method for this purpose.
But since I have not used IB, how can I resize the controls when they are in landscape mode? How can I position them correctly using code only?
In most cases you can get views to resize themselves appropriately just by setting their autoresizingMask property to some combination of:
UIViewAutoresizingFlexibleLeftMargin
UIViewAutoresizingFlexibleRightMargin
UIViewAutoresizingFlexibleTopMargin
UIViewAutoresizingFlexibleBottomMargin
UIViewAutoresizingFlexibleWidth
UIViewAutoresizingFlexibleHeight
For example, let's say you want a view's width to increase when you rotate it to landscape, you want it to maintain the same margins relative to the top, left, and right sides of the screen, and you want its height to remain the same. This means that out of the six attributes above, only the width and bottom margin should be flexible. The other four attributes are fixed. So you would do:
yourView.autoresizingMask = UIViewAutoResizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
In those rare cases when you can't get the views to behave appropriately using their autoresizingMask property, you can wrap them in a custom view and override that view's layoutSubviews method. This method gets called when the view's frame changes due to autorotation, so you can check [[UIApplication sharedApplication] statusBarOrientation] and update the frames of your subviews manually.
You position them correctly using code the same way you likely positioned them in the original orientation, for example by setting their frame.
As for where in code to do this, check out the various orientation change methods of UIViewController that will be called when the device orientation changes. You could, for example, move/resize the controls in the view within willAnimateRotationToInterfaceOrientation:duration:.

IPhone how to properly resize view when rotating device

I have been trying to resize my view inside a view Controller with no luck so far. Basically I have a button at the very bottom of my view and when the orientation changes from Portrait to Landscape the button is no longer visible, because its just too far down now.
How can I resize this view so that when the orientation changes the button is still visible?. I have tried setting
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
and basically every other possible combination, with no luck so far. I know I can do this by manually repositioning the button, but is there a better way to do this?.
Thank you.
-Oscar
The view containing the button must be auto-resized using your mask (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight).
On the containing view autoresizesSubviews must be set to YES.
The button must use UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin.

View shows only half of width in landscape mode

I have one view controller,in that i have 1 UIButton ,when i click on that button one view opens ,but when i move it to landscape mode at that time the view shows only half of width not full.what should i do?????
Thanks and welcome for answers
You may need to set the autoresizing properties, i.e.
myView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
You should probably call setNeedsDisplay on the view after changing the orientation.