Xcode 6: label won't drag - ios

Im just picking up ios development, and Im having a stupidly basic problem with xcode...
I open up a new app and open main.storyboard, and drag in a label to the center of the panel:
It just sticks to the right side, and no matter how many times I click on the darned thing, it won't move! I closed the project and started a new one, and that one worked just fine, but the problem keeps appearing just about every other time I open a new project. why does this keep happening?

That is a strange problem. You say that if you close the project and start it again, it fixes itself but keeps reappearing.
Few suggestions, try clearing up some ram by closing other, unused apps.
If that does not work, I would say delete Xcode, restart your mac, and start over. Maybe something went wrong during the install.

Storyboards are scrollable and when you scrolled out your views, you cannot make any changes to the views. Try scrolling into the storyboard and then retry moving the label.

It's AutoLayout, which is the highly recommended default for laying out components now. You need to create constraints to
position it, using the icons below the layout area.
Some components I've found I need to manipulate via the size inspector, before constraints are applied.
You will need to read up on Auto Layout sooner or later. It may seem like a hassle or drag at first, and a lot of people are cursing when they have to switch to the paradigm, but when you start to master it, it is very powerful. And it really is a sensible way to handle the layout across all the new screen sizes and orientations. It developed out of a need to manage that complexity to keep apps looking good.
Icons in IB where you set constraints for selected views:
Apple has good documentation for how to use Auto Layout as do many bloggers and sites. You will have to put some hours into getting used to it, but in a day or two you should start seeing good results.
(and don't blame me, I'm just the messenger)

Related

How to get iOS app to work on all iPhones? (Constraints)

I am fairly new to developing for iOS. I have a fully functioning program written in Swift and the UI was created in the scene builder on Xcode. I created an app for my work to simplify closing out the registers and other financial aspects. The app is complete and works perfectly, but was designed on the iPhoneX. The problem is that only a few of the employees have an iPhoneX, but they all have some kind of iPhone. I have tried setting up constraints but it never works. Ive tried scaling restraints and position restraints but I can't get the layout to look right on any other phone, and when I add the constraints it affects the view on the iPhoneX as well and doesn't look good on any iPhone. I need help getting this to work on all iPhones. I would like it to look and act the exact same regardless of the size of the phone, basically just scaled down. There are a lot of things on the screen and I can't figure out how to do this. Please help!!!
I have been working on this for a long time and I really need help. Please let me know if I need to clarify anything. I have posted links to some pictures of my UI so you have an idea of whats going on.
Constraints I tried adding, although I have played around with some other options.
Here's what it looks like on the iPhoneX, this is how I want it to look.
What it looks like on iPhoneSE (with constraints).
One thing I noticed in your Xcode project that none of your features are in UIView. Without it, it will be quite challenging and somewhat always different results. In theory, if you use AutoLayout features correctly it should work without UIView, but they make life so much easier. This is something I learned the hard way at the beginning of my iOS development. First set up your UIViews without any content inside it, give them some background colour to differentiate, once they are working on all devices. You can pin your features to superviews with no difficulty.
Since you have a repetitive features, you could also consider using Stack Views. You don't have complicated features, so as long as AutoLayout is set up correctly you should have no problems seeing it ok on all devices

Simple IOS Layout

I have been trying to do this layout for a few days now and cannot do it. I have no code as I have been only using Storyboard.
In my Android version I simply used a weighted LinearLayout where my title was 20% my relative layout was 60% and my custom object was 20%.
I cannot replicate this in IOS. Everything I try fails. I have tried everything and have tried using StackViews, EqualHeight constraints with multipliers and everything does not work. Most of the time nothing even happens and it just looks the same. Can someone please help me? I am so frustrated I am considering abandoning XCode in total and coding my app in React Native.
It's not really clear what you're asking. But if you want to use storyboards, it's pretty easy with XCode. You can set your layout visually, then simply use the "auto-resolve" feature (little triangle inside of bars on bottom right above the console) to: 1) "clear constraints" and then 2) "reset to suggested constraints". This is a fast and crude method that should more than enough to get started.

I have to update frame of everything in storyboard every time I start Xcode

So each time I open my project in Xcode, I have 100's of warning because the frames of every UI Object has been moved. I have to take the time and go to each UIViewController and update frames on it.
Is there a reason this happens? How can I fix this? Any other information I need to mention?.
Do you use a repository for your code? There may be some configuration file missing, probably not comited properly
In my case, this was happening because size-class for which I have set the constraints and layout got changed when I opens the Xcode project. So make sure that the size class remain the same for which you have applied the layout or change it if it has been modified by the Xcode.
If above does not work for you, you can try having a local repository created by the Xcode and commit the code before you quit the Xcode.
Hope this helps!!
I believe this was asked previously here:
Interface Builder degrades storyboards, resizes and repositions views in small increments
I have not yet seen a fix to the problem, but the answer I posted there likely holds true here.
https://stackoverflow.com/a/28577800/682574
At least one source is due to storyboards resolving layouts to either full pixel boundaries (x=7.0, y=10.0) or partial boundaries (x=7.5, y=10.5). As best I can tell, this can be recalculated any time you view the storyboard and the rounding is actually determined based on the current display environment.
You can intentionally cause this behavior by viewing the storyboard on a retina display and then viewing it on a non-retina display. With my dual-monitor display, if I just drag a storyboard from one screen (retina 5k) to another (non-retina) it will generate a flood of misaligned constraints. Unfortunately moving it back doesn't fix them! Try it out for yourself (or don't ... it's a pain to correct).
In a team environment its easy to see how this could happen as soon as two people with different setups view the same storyboard.
How to fix it? I haven't heard of a workflow that properly corrects or avoids the problem unfortunately.
Here are a couple of reasons I've seen for intermittently misplaced views. I'm not sure if either of these is responsible for the problem you're seeing -- usually these will cause a few views to be misplaced here and there, not every view in your storyboard. But I've listed them just in case it helps.
Different team members may be using different versions of Xcode, which may position certain views slightly differently, and which will certainly change the storyboard file "tool version" and so forth.
Constraints are not usually happy with fractional widths/heights in them. This can be difficult to detect -- for example, you may have a view whose intrinsic height is an odd number of pixels vertically centered within a view whose height is an even number of pixels, causing the inner view to start at a half-pixel offset and want to be repositioned lower or higher when the storyboard is re-opened.
For xib files, you can easily write a script that updates automatically the frames:
ibtool input.xib --update-frames --write input.xib
But, you should not worry about these warnings: the frames will be automatically adjusted during the execution.
Its could happens due to having 4k external display. Everybody in my team does not have this kind of problem, only me.
After opening Xcode tries to align logical points to physical pixels, so everything moves about 0.5 point.

iPad UIViewController subview reset issues

I am not really sure how to phrase this question but to keep it simple;
I originally started my app for iPhone but now made it universal. Being that did that, I started making iPad.xib files as well... Everything is complete now and everything is working how it should except ONE thing...
On the Controllers, I have an instructions button, (button that when touched, a uiview gets added to the center of the screen and says the instructions).
That all works great but for some reason when I touch it on one of the new iPad Controller (from the iPad xib) all the buttons that were moved around the view prior to touching the button, start to revert back to the initial position...
I do have a function that makes them do that, but to my knowledge, it is not being activated when this instructions button gets touched. If it were, I'm sure this "error" would also happen in the iPhone simulator...
Anyone have any idea? I keep looking at different solutions but can't really figure this out.
Thanks!!
This is most likely due to auto layout. If you change the frame of a view by setting frames, when the view updates (for any reason), the views will revert to the frames that are determined by their constraints. To fix the problem, you should move your buttons around using constraints, or turn off auto layout. While turning off auto layout is the easy way to fix this, you really should learn how to use that system.

Basics on how to setup horizontal paging in iOS app?

I've looked for this for a while, but I can't find any good guides or resources that explain it thoroughly (not even Apple's own documentation, which seems to not have as much information as I'd expect). I want to setup a basic interface that has 6 pages horizontally. Each page will have a bunch of labels and textboxes, but the layout will be the same for each page. Eventually, I want to be able to have each page scroll down to view all the content, but I'm assuming I just need to use scrollviews as the content for each page.
Also, each page will eventually have to have separate names for each textbox (and separate from the other pages too) because I'll need all the content of the whole app to be saved out later.
But really, for now, I just need to figure out how to get paging working. I tried following one demo but when I typed in the code, Xcode wasn't recognizing one of my classes (which I know I included it). Plus, I didn't understand what was going on really, and I feel that I need to understand what I'm coding.
Also as a side note, how do I start programming for iOS 5? I updated Xcode to the latest version which said it had support for iOS 5, but I only get up to 4.3 in my project target.
You can use this project http://cocoacontrols.com/platforms/ios/controls/icarousel, the only downside is it does not support cell reuse, so if you plan on having more than a 5 or so panels the app will really start to blog down.
For any future searchers that have found this thread, I was able to achieve what I wanted.
Basically, just make a scrollview the size of however many pages you want (multiply the width by how many pages you want and that will be the content width). Then just enable paging in interface builder and it will page through the view. Then you can just add content to the scrollview.
It's not hard. When I did it for some of my apps, I had a very detailed 'template view' which included primarily a tableview, but also lots of buttons and text fields and such. I was amazed at how well it all worked when put together -- no real trouble with gestures or anything. Apple's UIPageControl sample code is a good place to start.

Resources