Im’ new in auto layout with Storyboard in iOS 10 and I want to insert into in the View a button that In portrait mode its centered in the view and has a fixed width and height and for this reason I set right constraint and this works.
This is the screen on my situation :
My problem is this , I want to do this :
when device is in portrait mode button must have constrain that I described up(centered and fixed width and height) , but when device is in landscape mode I want that , for example , the button’s height is 400px.
How do I do this?
Related
As the title says:
Is it possible in xCode to make 1 view, lets say I make an app without auto layout just for the iPhone 5, and than stretch it depending on how big the screen size will get? The whole app is in landscape.
yes by using constraints
control drag from items (buttons , labels , uiimageview ) to your view and select your constraint
Place your view into your storyboard nicely, from edge to the edge, using e.g. iPhone 5 viewport size.
Then you may need to use something like this when autolayout turned off:
yourView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// check whether you have not this property set to false, it should be set true as default
yourView.translatesAutoresizingMaskIntoConstraints = true
I have a view with buttons optimized for iPhone 4. The buttons fill the whole screen. If the user have a phone with retina I want the buttons to still fill the screen. If the user have a iPhone 4 the buttons height are 148, but if the user have an iPhone 5 the buttons should now be 178...
iPhone 4:
http://i966.photobucket.com/albums/ae148/fostom/ScreenShot2013-08-17at94846AM.png
iPhone 5:
http://i966.photobucket.com/albums/ae148/fostom/ScreenShot2013-08-17at100649AM.png
Ok. I fixed this myself.
The solution for resizing the buttons from 3" screen to 4" screen is:
Select top row buttons. Set constraint ´Top Space To Superview´
Select bottom row buttons. Set constraint ´Bottom Space To Superview´
Select all buttons. Set constraint ´Heights Equally´
At least; this fixed my problem/question. This is purely done in storyboard and no code.
This can easily be achieved with a constraint like this:
#"V:|-10-[button1]-5-[button2(==button1)]-5-[button3(==button1)]-10-|"
You don't specify the explicit height of the buttons, you tell autolayout that all buttons should have the same height (button2(==button1) means that button2 should have the same height as button1). Then you specify the distance between the buttons (5 in the example) and the distance between the top edge of the first button, the bottom edge of the last button and the edge of the view (10 in the example).
et voilà:
If you want to set up your constraints in interface builder you have to convert them yourself. Shouldn't be that much work.
I have a tracker that is 320 pixels tall that goes in the center(ish) of the screen of my app and I want to place labels in the four corners of the tracker, so I made an invisible view the size of the tracker so that I could align the labels to the view's edges, but autolayout keeps resizing the view when the tracker remains 320 pixels. Is there a way to keep my view the same size (390px) on both 3.5" and 4" iPhone screens?
You can always add fixed width and height constraints to your view. Select your view and then chose Pin/Width and/or Pin/Height from the editor menu. The pin menu is also available from the middle segment in that control thingy in the lower left corner of Interface Builder.
To keep your layout from being ambiguous you then might have to remove some constraints from the size inspector of the utility area.
I have an app that is designed for the iPhone 4. This app has a toolbar that was drag-dropped in Interface Builder to the bottom of the screen. When testing on simulator's iPhone 5 "device", the toolbar does NOT automatically go to the bottom of the screen.
My question is - is there some kind of a trick or technique, that will let all the UITables "stretch" to populate all the new available space, and toolbars go to the bottom no matter what kind iPhone it is being connected to? It would be painful, to do this programmatically - that is figure out what kind of an iPhone I am and then, programmatically reposition all the ui. If this is in fact a must, should any new iPhone apps be designed for 4" retina, and then programmatically shrink everything for iPhone 4 size, or is it better to design for 3.5", and then stretch and push down toolbars in case it is an iPhone 5 with 4" screen.
Thanks for any input..
If you are only using iOS 6, the easiest method would be to use Auto Layout and add a constraint in Interface Builder. The constraint would describe that the toolbar's bottom edge should be equal to the superview's bottom edge. You don't have to code specifically for a single device. To have the UITableView stretch to fill all the available space, again I would recommend using constraints on the UIScrollView (not UITableView, which sits inside the scroll view) to describe this behavior, e.g. The scroll view's top edge should equal the superview's top, left edge should equal the superview's left, bottom edge should equal the UIToolbar's top (In IB, a spacing constraint specifying that the spacing between the UIToolbar and the UIScrollView should equal 0), and right edge should equal the superview's edge.
If you can't use constraints, this behavior is specified using the struts and springs system that utilizes the autoresizingMask property on the view that specifies that the UITableView's parent-UIScrollView has a flexible width and height and the UIToolbar has a fixed height and a flexible with. You would manually position the UIScrollView and UIToolbar by setting their respective frame property that describes the x,y coordinates of the top-left edge as well as the width and height of the view.
View Programming Guide for iOS - Adjusting the Size and Position of Views at Runtime
Cocoa Auto Layout Guide: About Cocoa Auto Layout
I have few text fields in sectioned table view. When i rotate the view gets rotated according to the orientation but not getting filled up according to the screen. For instance i have set the width using CGRectMake method for portrait as 70.0 but when it is turned to left the size of the text box is the same and not getting expanded according to the width.
I have the widths setup in my tableview code according to the orientation. Please tell me how to reload the tableview after the orientation change or what is the way to make the CGRectMake to change automatically based on the orientation for each component in table view.