Subviews of ViewControllers shifted to the left in iOS 7 / XCode 5.0 - iphone

I've got a project in XCode 5.0 that I ported from XCode 4. Most everything in XCode 5.0 makes sense, but I can't seem to figure out why some subviews of my view controllers are shifted to the left when I compile and run the app.
1.) I have a tableview inside of a view in a view controller. The containing view is freeform portrait with no status bars. It is 520 by 520 in interface builder, centered. When I compile the app, the table view isn't wide enough to fill the width of the view that contains it. The tableview appears to be shifted 30 pixels to the left.
2.) I have disabled auto layout. I hate auto layout for a number of reasons, mostly because I really like to tell Interface builder exactly where things need to go in specific screen configurations. (Please don't preach I just hate relative layout schemes and am willing to do extra work to avoid them).
Does anybody know what might cause the widths of subviews to change in XCode 5.0 ? I have temporarily set the frame manually in the code, but it's really weird because I need to specify a width that is approximately 20 - 30 pixels wider than what I originally had.
Any idea where this difference is coming from?

Related

Swift 4/Xcode 9 - UITableView custom cell getting cut off on the right

I'm having trouble setting constraints on a tableView that I've inserted into my View Controller. It's occupying around half of the view and despite pinning it to the sides of the view, it seems to maintain the same size dimensions when I switch to a smaller iPhone causing it to overlap on the right side. I'm using a custom cell with 2 labels. I've tried the suggestions in this thread with a similar question: AutoLayout labels getting cut off on right side of screen but haven't had any success.
Here is how it looks when being viewed on the iPhone 8 plus
and here's how it looks on the iPhone SE.
Here are the constraints that I set for the tableview.

UIButton images look fine in IB but get stretched when displayed on app

I'm developing an Enterprise app for tracking mileage and maintenance for company vehicles. I've added graphic buttons to snazz it up a bit. The buttons look the way they're supposed to look on the XIB in IB, and on the iPhone all other UIViews look correct, but on one particular UIView the graphic images are stretched way out of proportion vertically.
The first image below shows how it's supposed to look, with the three graphics buttons at the bottom. The second image shows how it's showing on the phone. The Help button on this screen cap shows normally, but it can't be counted on to stay that way.
It also is not consistent. Calling this view at any time may show the image stretched or it may not show an image at all. It rarely shows the image normally, like the Help button looks below.
The development phone is a 4S running 6.1.3. The views are set for the Retina 3.5 screen. XCode is the latest (whatever it is).
Again, it's only on this one view that the problem shows up. There is another UIView on the same view controller that is hidden when this UIView is shown. The button graphics on the other view look fine. All of the other views and view controllers use the same graphics on the UIButton, without any problem.
In Interface Builder (Xcode) you created the view using a 4.5-inch screen height.
But the device where you are seeing the problem is a 5-inch screen. So the view is resized to fit.
And when it does that, the autolayout constraints that Interface Builder put on those subviews take over to determine what they do. Those constraints are causing the heights to change.
No need to turn Autolayout off. Autolayout can be very useful, but it seems to enjoy randomly assigning the constraint "Align Baseline to:" to UIButtons after repositioning them.
Just select the UIButton/UIImageView in question inside Storyboard, locate the constraint "Align Baseline to:", tap the gear icon and select "Promote to User Constraint", and tap once more and select "Delete". This should solve your issue.
In response to the comments here, I will answer my own question: I turned Autolayout off for this view controller, and that fixed everything. This is the first app I have written since XCode has begun development for the iPhone 5, so I wasn't aware of the Autolayout feature. I'll need to understand how it works and why it did what it did.
Thanks for all your help!

Xib Size - seems to think its longer than it is

This is a bit of a strange one, but basically I am having a problem whereby the xib size of my initial view controller seems to be longer than the screen.
So, if you have an ad banner set to be on the bottom of the screen... If I run the app in simulator, it does not show on iPhone 3GS/4/4S devices, yet WILL show on the iPhone 5.
I have tried changing the xib size settings, I even created a new xib file, but the same problem is occuring which leads me to believe it is hardcoded somewhere, but I cannot think where to look for this.
It is basically like it thinks the bottom of the screen is about 30-50px more than what it actually is... Hence why the iPhone5 displays ok as it has the taller screen.
Any help would be appreciated!
Its bcoz of the StatusBar. It reserve 20px of screen . You can remove this space by do change in Status bar is initially hidden in plist and set status bar to NONE in IB.
The iPhone 5 has a taller screen. The most flexible way to lay out your xib is via AutoLayout. Here is a tutorial to get you started:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2
Basically, you want the ad banner to be contrained to the bottom of the view.

Problems when trying to support 3.5 and 4 inch screen of iPhone

I started the development of a new app on the iPhone 5 and now I also have to add support for 3.5 inch screens. As you know, there is more space for content on a 4 screen than on a 3.5 screen.
When I run the app on a 3.5 screen, the whole layout is messed up. Is it possible to use the layout normally on a 4 inch screen, but place the layout within a scroll view when run on a 3.5 screen?
My idea was to scroll the page rather than completely redesigning it. How can I achieve that?
(or maybe it is somehow possible to design a layout for the 3.5 screen and the 4 screen seperately)?
It is totally possible to design completely different layouts for 3.5 and 4 inch screens. You would just need to add this :
#define IS_IPHONE_5 (((double)[[UIScreen mainScreen] bounds].size.height) == ((double)568))
And build separate cases, using if (IS_IPHONE_5) {do this...} else {do that...}
BUT
This should be done only as a last resort, because it would require a lot of manual/extra coding. You should ideally create the view in such a way that it automatically adjusts itself for both the screens. And you can do that in 2 ways :
1)With Auto-Layout i.e applying constraints on and between each view element. (Personally I don't like it a lot)
2)Without AutoLayout, by applying auto-resizing masks on each of the view elements. (and checking by toggling the form factor button in storyboard)
For that u need to add image of size 640* 1136 with name Default-568h#2x.png and addded to the image folder and then add the image in the Target-General- AppIcons
It very simple and it worked for me
I wouldn't suggest ScrollView since, if you go by that Method then there will be a lot of reframing of the UI ELEments
If You contain few elements then I would suggest go by AutoLayout or AutoResizing Mask, set your constraints in such a manner that they expand and contract depending on your views height,
or
If your View contains a lot of UI ELements that the constraints conflict then and only then go For Two XIb files in your App corresponding to the same class (set your ClassName to the Two Xins in identity Inspector), If you are using Story board then just Duplcate your Current View and Adjust it for iPhone 5 and set the StoryBoard Identifier different for each, and Then based on the Device height load the Views Respectively such as
if([[UIScreen mainSceen]bounds].size.height>480){
//Load iPhone 5 View
}else{
//Load iPhone 4 view
}

UIView is shown displaced at the top of the screen

OK, hopefully a stupid question from a newbie...
I have an app that used to display fine base on XIB files created in UI Builder. The .xib still displays fine using the simulator direct from the UIB but when compiled and run, the view is displaced by 40 or 50 pixels (about 1/3 the width of a nav bar) so that I get a bar of white space at the bottom and half my title text hidden on the nav bar at the top.
I have tried fiddling with various parameters for the view and main window (eg layout wants full screen and resize view from NIB) but nothing seems to make any difference.
I tried upgrading xcode from 3 to 4 but no difference.
Any pointers gratefully received...
I don't know about your specific scenario, but layout problems usually boil down to inappropriately specified autosizing parameters.
Pure speculation:
Fiddling around in Interface Builder, in the typical template xib file, you can get two windows to draw your interface on. One of them refers to the window, the other to the view controller. You should leave the window alone. Anything you put in there is placed relative to the window, i.e. the screen. This would typically lead to what you describe.