Designing without auto layout so that it works for every size device - ios

I'm designing an iOS app in Swift, not using auto-layout. I'm not using auto-layout because if i do, when my labels update, the design resets. For now, I'm designing for an iPhone 4.7 inch, but when i run it on the simulator for any other size device, the design is completely messy.
UPDATE:
I designed my storyboard with the proper constraints. I added my UIImages in the override func viewDidLayoutSubviews and positioned them outside of the screen. When a button is tapped, there should be a sequence of animations which are triggered as well as a UILabel which should have its value updated.
I commented out some code and kept running it to find the problem, and I found that the UIView reset whenever the UILabel updated. The values are being queried from Parse.com.
The design works when the label is NOT being updated. But once the value changes, the view resets...
I tried disabling auto-layout and it works. However, if I have auto-layout turned on it doesn't.
What do I do?
Thanks in advance

You should really use Auto Layout. It is the way forward for UI layout. The problem with your labels can surely be fixed with proper constraints.
Make sure you modify constraints instead of frames. The layout engine will calculate the new frames when needed, as helpfully mentioned by #rdelmar.

Related

Auto-layout features not working in a table view cell in xcode?

I am making a simple app since I'm quite new to xCode. I have a table view which holds cells. I've added constraints that I was hoping would dynamically change the width of the cell depending on the device (iphone vs iPad). However, it doesn't seem to be working.
I believe I've set all the necessary constraints, but I guess I must be missing some.
Here is an image of what I'm working with:
And this is the problem, when I change the size of the device I'm working on, the labels in the cell don't resize themselves.
Here are the constraints I'm currently using:
Any help would be appreciated, thanks.
Most probably you haven't updated the frames after changing the size of the view controller

Auto Layout implementation in already developed app in Xcode 6

I have already developed an IOS app in Objective C, Xcode 6 in which I have disabled the auto layouts and size classes.
Is it now possible to use auto layout after having disabled it earlier?
If yes, how can I implement it? When I enable the auto layouts and size classes and I implement the constraint on the label, the background colour of the label changes to white. When I do this for other object types, they become invisible.
To answer your first question, yes: it is indeed possible to use Auto Layout in an app after having disabled it. Each Xcode project template just gives you an initial starting point – nothing is set in stone.
For the second question, the best way of implementing Auto Layout in an app is to just take it one view at a time. You don't need to go all-or-nothing with Auto Layout; it's possible to just use it in certain cases but use frame based layout in others. Start on smaller, easier views and go from there.
The last issue around background colors is a little trickier without having screenshots or code samples. I have had views disappear on me after implementing Auto Layout and the issue always boiled down to bad constraints. The best solution I can give there is to just do the usual view-debugging work (as in, printing frames and manually setting bright colors to see where views actually are) and figure out what is going wrong.
Having the background color change to white is interesting, though... Auto Layout should not be affecting that at all. It sounds like the background color got changed somehow while the constraints were being created.

Xcode 6 view controller showing blank screen with autolayout

I'm trying to use view controller that I decided to use auto layout for. Before I used auto layout, the view showed normally like how I intended it to during runtime. But I decided to switch to auto layout (because after all, bigger iPhones are coming), and even after setting it up, getting no issues at all, and seeing that the app scaled well to the iPhone size in IB; I still have a blank screen. To prove it, here are pictures:
So why is this happening? I added the constraints in the square view, and it gracefully scaled to the iPhone view in Interface Builder. If you also look at the sidebar, the alerts for auto layout errors are not present. And IB is rendering everything. But why is the simulator blank?
And yes, I connected all the elements to be code correctly. I verified. And yes, I have code that puts text in a label. Here it is, in the 'viewDidLoad()' method:
override func viewDidLoad() {
super.viewDidLoad()
self.titleLabel.text = "Hello, World!"
}
And I will reemphasise: the app worked before I did auto layout. For this build, I deleted all the elements, relocated them, reconnected them, and added tweaked the view with auto layout unit IB rendered it correctly. But I'm getting different results here.
Please help me. Oh, and sorry for the massive images, I can't figure out how to shrink them.
EDIT: I've gone through and used the view debugger, and tried to capture the view hierarchy to look for clipping or occlusion. Funny enough, the view debugger shows the content properly, and there wasn't any clipping or occlusion that I saw. When I tried to show frames in the simulator though, it didn't show anything. I'm starting to think that this is a simulator bug. Currently, I'm using Xcode 6 beta 6.
I recreated the issue by adding a collection view to a standard view controller and this seems to be the problem:
Having Xcode add suggested constraints gives you this, which causes the view to not show up.
It is aligning the view's left and right to the layout guides (which doesn't seem to be right)
You will have to manually add spacing constraints to your view.
This is what you want:
Try turning on the assistant editor and use Preview while tweaking your constraints.
(source: mattknott.com)
Do your Editing in "wAny hAny For All Layouts Base values" mode. then you will not see blank screen while testing on different devices.
Mode selection can be one from bottom bar.
Good Luck

XCode 6 GUI Not Updating

I am using XCode 6 to make a simple calculator using Swift. Anyway, I compiled the code with the initial GUI and it works. However when I change the positioning of some buttons, it does not show up in the compiled app running on iOS simulator. Does anyone know what should be done?
Also, I've changed the code as well, and the code is updated. Ie, pressing button 1 will show 1 in the main textbox, but the interesting thing is the position of the button, which I have changed, still remains in the same position I set it to be initially.
How are you changing the positions of the buttons? If you're doing this by setting frames in code, and your original GUI is laid out in a storyboard, then you're probably fighting against auto layout.
Your storyboard layout will be driven by constraints, which determine the size and position of all the elements of your GUI. Setting a frame manually doesn't change these constraints, so the layout engine resets everything.
Either turn off auto layout (bad idea, since you now have to cope with every screen size manually) or move your buttons by adjusting your constraints.

Pinning width on UITableView using auto layout does not behave as expected

I'm currently busy designing my custom view in a seperate view xib file using auto and is really struggeling to figure this one out.
The problem that I'm facing is that when I set a fixed width constraint (pin width) on the table view say for instance 320 points (in landscape mode), as soon as I test the view by setting the orientation to portrait the contraint is lost and the table gets shrunkken down to 65 points?
What exactly am I doing wrong here or why is that? Or maybe I'm just missing something?
Thanks
I recommend to use the new autolayout-option of iOS 6 only in very special cases. I have tested this option very intensively and find out a lot of bugs, e.g.:
in the console appear messages indicating apple bugs
it slows down your UI dramtically
while layouting constraints suddenly disappear
the app sometimes crashes with undocumented error messages
Using autolayout is currently very frustrating. Instead of using autolayout I use
- (void)viewDidLayoutSubviews {}
to adjust my UI programmatically, which is much easier and faster (at developing and at runtime).

Resources