Change Text Alignment in UITableViewCell On Rotate - ios

I am using sizing classes to turn two xib files (iPhone vs iPad) into one. Most orientations have a 2x2 grid of UILabels above a UITextView. However, for iPhone portrait, I want the UILabels to stack vertically. I have this working great with sizing classes. I was disappointed to see, however, that sizing classes don't allow for the change of text alignment. Refer to my diagrams below. In the main orientation I have the text in the yellow and blue UILabels right-aligned. In the iPhone portrait orientation I want the same UILabels to have left-aligned text. How can I change this if the user rotates the device while viewing these table cells? I figure there's a better way of doing this than reloading the table.

I dont think it is possible to setup the text alignment based on the screen orientation or device. however you can create 2 labels, one with left aligned text and the other with whatever you're using otherwise, in a way that they are exclusive to the screen layout you're using. I.e. one label for iPhone and one label for everything else.
You can select then, for that UILabel object in storyboard, which screen layouts it will be installed for.

Related

iOS Storyboard: Different Layouts for Different Devices

As you can see, this is the different device previews for my current storyboard. The transparent green on the bottom is taken up by another view controller, but the spacing needs to be fixed for each different size class. I tried setting the width and height in the storyboard to the setting I want to change, but it changes that attribute for all the size classes. How can I just change, for example, the size of the Label at the top for ONLY 3.5in iPhones or the green layout for ONLY 5.5in iPhones?
Choose the pin of the label and go to Attributes Inspector of the Utility Area. You can find + button left to the constant text field.
When you tap the button, you can choose the size class you need.

Maintaining consistent spacing with autoresizing masks for three text fields

On my iPad storyboard, I have 3 text fields with a consistent spacing in portrait mode. I assigned autoresizing masks as shown in the image below, but after rotation to landscape, there is a gap between the second and third text fields.
If I want to maintain the left and right margins after rotation (currently on the first and third text field masks), is there a way to specify that these three text fields should be resized in the same manner?
The storyboard does not currently have auto layout or size classes enabled.

Size classes and storyboard in UITableView

I need to add 3 labels to my UITableViewCell when my phone is in portrait, but when it's in landscape mode it should display 5 labels. Just to add complexcity when same cell is in ipad landscape it should show 6 labels. It should look something like this.
iPhone portrait
iPhone landscape
iPad landscape
I can do this using diffrent UITableViewCell XIB's but I want do this using Size classes and storyboard. Is there any example / tutorial / suggestion to follow ?
What you're looking for is this tutorial by Apple:
https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/EnableAndDisableViews.html
This panel will install a given view for a given size class, in other words, make sure it exists or doesn't exist:
(source: apple.com)
This still doesn't give you the opportunity to change it for iPad specifically because the size classes aren't distinguishable but perhaps you could smuggle as I think the iPhone has it's height as Compact in that mode and the iPad and iPhone 6(S) Plus as Regular. So you need to add that extra label in the width looking at the combination of Regular width and height.
Also make sure you install the right layout constraints in more or less the same way as in one scenario you space to the next label while in the next scenario that label is gone and you need to space it to the right side.

Xcode - Adding constraints to UITableView so that it fits all screen sizes

I've read quite a few tutorials and watched numerous videos on using constraints in Xcode. For some reason, I'm still missing certain aspects that are necessary to make the user interface look the way it's supposed to for all screen sizes.
Currently, I have a UITableView laying on a view controller. The view controller is set to "Inferred" size and I have all of the different sized devices open in Assistant Editor Preview to the right so I can view the changes. I've encountered multiple problems attempting to get the constraints correct for the different screen sizes.
Problem 1: The UITableView has a width set to 600. This causes dead space to the right of the table view on the iPad preview and it causes the UITableView to extend too far on the smaller devices. If I make the width of the table view smaller so that it fits within the preview of all screen sizes and then pin the left and right edges of the table view to the edge of the Superview by specifying 0 and unchecking constrain to margins, the result I'm seeing in preview is that the entire table view disappears completely from each device size. I was surprised by this because I thought by pinning the table view to the margins, it would make the table view fit within each of the screens.
Problem 2: (This is a completely different scenario from Problem 1, above.) In this situation, I've left the size of the table view to 600 and just specified constraints for the internal components of the cell contained within the tableview. In this case, the table view is still slightly not wide enough for the iPad dimensions and it extends too far on the smaller devices which makes components in the cells to be truncated and off of center.
I've primarily been working in Storyboard with Any width, Any height set. However, if I change the setting to Compact width, Any height, I can alter the constraints to fit the smaller devices a little better, but there's still a problem with getting things to work between the 5.5 inch screen and the smaller devices.
I would like to get my UITableView to extend all the way to the edges on each device and I would like to have the view inside of the cell remain centered and keep it's relative size on each of the devices. Does anyone have any suggestions on how I can accomplish this?
if you want to make your tableview to "fill" the whole screen (device-independent) the only thing you have to do is to pin its 4 edges (top, left, bottom, right) to its superview (the viewcontrollers view in your case) with a constant of 0.
you do not specify a specific width (like in your case 600) or height.
good luck :)

UITableView height problems in Retina 3.5-inch

If you look at the screenshot, showing a list of US states, "WV" is not the last row, there are two more rows after: "WI" and "WY" which extend beyond the bottom of the layout. This used to work with Xcode4/iOS6 regardless of whether or not you were in 3.5-inch or 4-inch. Now this only seems to work for 4-inch but not 3.5-inch.
Does anyone know how to get the height behaving correctly for Retina 3.5-inch?
The orange background in the storyboard screenshot below is the View background color.
You need to use the buttons in the lower right-hand side of the interface builder. Specifically, you can use the "Pin" button to create constraints to the top/bottom and other gui objects.
Constraints in Xcode4 used to auto-create if you dragged an object to the edge of the screen but not anymore in Xcode5 which is why I was confused.

Resources