UILabel in different position for 2 different screen sizes - ios

I have a UILabel that i placed in the top left corner of the screen in the Storyboards. I disabled "Autolayout" and it works perfectly fine on the iPhone 5 screen. The problem comes when i try them on any of the smaller screens like the iPhone 4. The label is then placed on the bottom right corner. After this issue, i tried to programmatically 'fix' the position in the "viewDidLoad" method of the view controller, but it stills moves position and the problem continues.
Ive been scratching my head about this for a while!
Any help would be appreciated.

I would suggest that you turn autolayout back on. If you get the constraints right, this situation (two different screen sizes) is exactly the sort of thing autolayout is really good for. There's a very good reason why Apple migrated autolayout from OS X to iOS at exactly the moment the iPhone 5 screen appeared on the scene!

try to fix it at viewWillAppear

Go to the utilities panel, click the tab "Show size inspector", and change the autosizing. Then drag your component in your storyboard's view so that it stays in one of the "borders". If you do not need to support older iOS versions, I'd recommend you to figure the proper way with auto-layout though.

Related

Xcode UITableView image does not align properly on simulator

I am working on a project on Xcode7.3 using swift using autolayout. I am stuck with an problem with the UITableview not displaying properly on the simulator.
I created a ViewController and dragged a TableView into ViewController. Then I dragged a UIView and UIImage ontop of that TableView (To display as a header image). I also dragged a UIImage onto the prototype cell. They are all aligned in the center horizontally and vertically. However, when I run the app, they don't show in the middle of the screen.
As shown in the UITableView_Problem Image, the images are offset to the right. What is also weird is that when I rotate the screen, the scrollbar on the right does not go all the way to the right. The images appears to be in the center of the screen if I consider where the scroll bar is the end of the screen. But that doesnt make sense because the bottom bar items spans the full width of the screen.
However, if I create a UITableViewController from the story board instead of dragging a TableView onto a ViewController, I do not have a problem at all. (Image3)
It is frustrating because I wanted to add a text field for keyboard at the bottom of the screen just like the comment section in Instagram app. And after hours of searching, it appears that the only way to do that is to drag a tableView onto a ViewController. i stack imgur com JC5Pw png
Could anyone please assist? Much appreciated
Blockquote
note: I dont have a developers account yet so I cant check on an actual device
You are designing your interface in the wRegular/hRegular (or universal) size class. You will need to be very good about your constraints or develop a layout for the wCompact/hRegular size class for iPhones in portrait mode. You can change this by selecting here the blue part on the bottom of your storyboard
Thanks Dan for your prompt response! I added constraints to everything except for the tableView. Dont know what I was thinking as I have been troubled by this bug for a few days. Everything works fine after the tableView constraints was set!

iOS app only showing half in simulator

I am trying to develop a simple app with one screen for iOS and am running into a strange problem. Only half of the app is showing up. For example I have a screen with just one button in the center of the screen. When I run the app in the simulator I only see half the button and I cannot move it either.I can scroll the view in the simulator vertically but not horizontally. I am stumped. Will appreciate any pointers.
I'm pretty sure you built your view using the main storyboard and put everything in the middle of it. The main storyboard is set to take all iOS format into account, iPhone and iPad. If you want your app to appear centered on your iOS device, you need to constraint the position of your different UI objects, using Auto Layout. That way it would appear centered automatically, whatever is the device you're using
I reckon you've got AutoLayout turned on... but haven't set any constraints on your controls yet.
Try the following test:
Go into your Storyboard file.
Click on a blank area in your storyboard, then on your screen (so the border of your screen is blue - not black or gray).
In the menu bar, click on Editor \ Resolve Auto Layout Issues, and then "Update Frames".
Alternatively, you can click on the following button, and select "Update Frames" from there (it doesn't matter which one):
When you do this, where does your "one button" end up ? Does it suddenly disappear off the screen, have a negative X or Y position, or a width/height of 0 ? If so, then AutoLayout is your problem.
With XCode 6.1, Apple has put a gun to developers' heads and demanded that when you add an object to a Storyboard, you must - straightaway - add some constraints to it.
I had this issue when I first upgraded to XCode 6.
I would add, say, a View to a screen, stretch it to a particular size, then drag a second control (perhaps a Label) onto the same screen. Suddenly, my View would resize itself to a height/width of zero, or be positioned way off the side of the screen... huh ?!
To get around this, when you add a control onto a Storyboard, you must add sufficient constraints to really let XCode calculate where to position it, based on which device/orientation the device is running on. And, yes, you sometimes need to do this straightaway before XCode ridiculously decides to mess up your control's position or size.
I really do loathe XCode. This isn't the way a development environment should behave in 2015...
If I get your point of problem then
I m sure the problem is you have auto layout and size classes enabled.
check if you have Auto layout and size classes enabled ....???
If yes then you haven't set the constraints accurately. set the constraints for the UI Objects to show on your desired position in screen.

Developing on an iPod iTouch - UIView Issues

So I've been using this site for a lot of my questions. I'm very good with Googling problems and debugging even the worst error code, but this is something rather basic that I'm not able to figure out.
My UIView compared to what I actually see on the iTouch has always been a bit different. I'm not sure if this is xCode's IB just having larger graphics for its buttons, but in general there is this 20px height difference, to the point where if I set a button at the bottom of the UIView, it gets cut off. (I thought it was supposed to be 320x460..)
Normally I shrug this off because it hasn't been an issue till I've started to put scrolling into place with the login screen. xCode claims my view is 320x548, my app says its 320x480. If I resize my scroll size to 320x480, the view shrinks on the iTouch, leaving a large gap.
I have been using UIViews in the IB rather then a ViewController because I'm subviewing mixed with some nav control.
Is there something that I'm doing wrong?
http://oi49.tinypic.com/rrnjit.jpg (when first loading)
http://oi50.tinypic.com/j8matu.jpg (scrolling down about 20 px..)
You need to make correct use of springs and struts or Auto Layout. You are probably designing your app for the 4 inch screen - in your Storyboard, there is an option to see how it would look on a 3:5 inch screen. Press that.
For more info, Google Auto Layout.

ios - simulator looks different from the layout on the storyboard screen

I am having a strange situation. I created a very simple screen with some buttons on the storyboard, then when I ran the emulator (is it correct to say simulator or emulator?) it got the spacing wrong for one of the buttons.
I am adding a screenshot. The emulator is to the right of the storyboard screen.
Any idea why this may happen?
I thought it was a problem with the button. And it might have been. But when I took out two lower buttons, I got something even weirder as shown on this screenshot:
Thanks!
It looks like you are using Autolayout, and all your buttons except Investment has a Top constraint while Investment has a Bottom constraint, causing Investment's distance to bottom to stay the same when the screen grows taller.
Click on Investment button, click [Editor -> Pin -> Top space to Superview] in the top menu.
Click Investment button again. Click the second tab from the right in the right panel (the one where you can set frame). Look for a Top Space to Superview constraint, right click and delete. If there isn't one, then XCode did its job. Try running simulator again.
Edit: I just want to say that XCode has a habit of adding Top constraints for you when the view you just dragged into the xib is in the upper half of its container, and Bottom constraints when it's in the bottom half. I know XCode is trying to help but it drives me crazy sometimes.
It looks like you're using a 3.5" simulator and laying out for a 4" device, so the view will be resized.
If you're using autoresize masks, are some of the autoresize masks on your buttons incorrect? You probably want them all to stick to the top of the screen. Check to make sure the autosizing for each of your buttons matches this image. (You'll need to click the "ruler" icon to see these settings.)
I assume that you're using the XCode4 which provides NSAutoLayout as default. When you place an object to the storyboard NSAutolayout automatically creates constrains which layouts the object on the screen automatically for different devices(iPhone4,iPhone5) or orientations(portrait/landscape). Please check NSAutolayout class and constrains. if you want you can remove the NSAutolayout and your objects will be displayed on the simulator normal but in that case you have to manually adjust your objects for different orientations and screens
Hope helps.

Storyboard layout not correct on iPad 2

I am trying to lay out objects on a Storyboard using the interface builder yet when I run the app on an iPad2, the layout is being messed up and objects are not appearing where they should. All the objects are there but they are being moved horizontally and not the same number of pixels! For instance, I have two ImageViews overlayed on one another (one is 100x100 and one is 75x75 centred within) but when the app is run on the iPad, they are both being moved horizontally across the screen by different distances!
I'd like to add screenshots but unfortunately I can't for privacy reasons.
I know it's vague but does anyone have any ideas on where to start looking to fix this?
Thanks.
I had this problem too when I was first making an iPad app.
Try fiddling with some of the 'struts & springs' of the interface elements in the storyboard. To do this, select some of the interface elements, then on the right panel go to the size inspector and try some things with the 'Autosizing' rectangle.
Hope it helps!

Resources