This issue is really frustrating and getting me crazy.
I've read everything about AutoLayout and so on, but it happens all the time.
My interface has a view with an image view as background and a smaller subview on top of it (corresponding to a field in my image). I've tried everything but it looks like the subview does not scale accordingly with my image when switching through devices.
By the way, the IB preview does not show what i real get when running the iOS Simulator, is that normal?
Why? What do i do wrong? I'm not sure what else to try!
http://i58.tinypic.com/34xqtc6.png
EDIT: i cannot post images :(
I have setup a githubrepo regarding your case, kindly have a look
https://github.com/usamaiqbal83/TestingProject
Constraints for Background Image View:
Constraints for Front View
the most important thing to remember is ofcourse the constraint equation
FirstItem.Attribute1 = (SecondItem.Attribute2 * Multiplier) + Constant
Instead of subview use Container View.
Related
I want to believe this is a simulator bug, but, can somebody please explain what is going on?
Im running a simple View on my storyboard: (as you can see, the view with green background is my superview). The thing is when I run my app on a simulator (sometimes, not always) my superview doesn't get scaled and I get a black screen!! My view has checked true the Use Autolayout field, cause some things inside need to have constraints.
I can't give constraints to my view because, it's the superview
And yes, I have debugged with the UI and this is the thing, my superview is not resizing.
Okay I solved, for sure is a bug of Xcode. For me was very strange, so, I decided to delete my View Controller and add all my elements again.
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
I'm trying to use Auto Layout for a custom Table View Cell in my app.
I can't seem to get the constraints quite right.
I layed the labels out in the custom Table View Cell, but the labels are still getting cut off. Any ideas?
Thanks! Will post anything else needed. Tried to show needed info in picture below:
Debugging in Xcode. Somehow what shows in Simulator looks different than in Xcode debug.
Here's the width of my TableView shown:
UPDATE:
The problem here was related to what user matt said in the accepted answer, but I wanted to make the Q&A a bit clearer now that I have it figured out for anyone else that comes across this.
In his initial comment, he mentioned the Xcode View debugging, which was great and I was able to dig into a little bit more. Its called the Assistant Editor: Device Preview, where you are able to see the layout and layers of what is onscreen to see if maybe you have labels overlapping or going offscreen based on the device it is running on. If you want to check multiple device sized, just hit the plus icon in the lower left hand corner of this picture.
This helped me find overlapping layers and sizing issues with the TableView. I was able to see how it looked on each device size.
What also helps here sometimes to use the Pin menu. Sometimes the labels can run off screen because it doesn't know where the constraints of the cell are based on the device size. So your label can run offscreen if the label is based off of a landscape layout but the device is an iPhone 5 and is in Portrait for example. This is the Pin menu:
Hope that makes sense and gives some more color to the problem. Let me know if you have any questions at all, thanks for the help everyone!
The problem is that you are using auto layout but you have not done anything about sizing the table view. The table view here is not your view controller's view; it is a subview. Your view controller's view is automatically sized to the size of the device / window, but its subviews are not automatically resized. So you are ending up with the table view much too wide for the device; the whole table is sticking off into space on the right side.
Use a trailing space from the right side of your labels to the edge of their superview, and set it to greater than instead of equals with a value of ~ 5
Review the constraints of your tableview with the View. Draw cell border, label border and tableview border with different colors to know which elements do not display correctly.
Ex:
#import <QuartzCore/QuartzCore.h>
...
cell.layer.border.width = 1;
cell.layer.border.color = [UIColor blackColor].CGColor;
The thing that worked for me to solve views being clipped was to uncheck "Constrain to margins" in Auto Layout.
I have UIScrollView in which UIImageView is held like on the screenshot:
My problem appears when I zoom and instead of being able to scroll only in the area of my image (subview of scroll view) I'm able to scroll around the original size so I get a lot of white space around my image which isn't what I want. You can see what happens on the screenshot below:
I wonder what should I update to keep my scrolling area only the size of the image?
After some research, some trials and errors I've finally achieved what I was planning to do.
First of all, I wanted to use only autolayout with IB which sure can be done but with some effort. After some digging I've found this technical note which by "Pure Auto Layout Approach" understands adding contraints in code but I was aiming at only IB which led me to this simple but beautiful solution called ios-imagescroll. After investigating this code with joy that I've finally found solution I came with some error but only on iOS 8 devices... iOS 7 worked like charm out of the box.
I assume that due to big changes in iOS 8 autolayout is more strict and you must be 100% sure what you want to accomplish. It turned out that this slight change MATTERS on iOS 8:
Of course, this bug, fix (call it whatever you like) was fixed by experimenting with everything but I guess that UIScrollView's content view (in that case UIImageView) must be the first item in constraint.
[yourScrollView setContentSize:CGSizeMake(yourScrollView.size.width, yourImage.frame.origin.y + yourImage.frame.size.height+35 )]; //let's say just 35 ...
yourImage may have x,y origins like (0,0) [I see a lot of space above it, so I assume you have set other values for x,y]
I have a very simple situation: in a view i have an UIImageView and one UILabel. at a moment in time I want to change the position of the label and in the same method to change the image of the uiimageview.
self.myLabel.center = CGPointMake(158, 230);
self.myImageView.image = [UIImage imageNamed:#"anotherImage.png"];
But this code will change only the image and will not move the label. If i comment out the second line and run the code then the label will change the position.
Dose anybody have an idea why is not working? Or a valid workaround for this problem?
I just tested the above code and it works fine. When the keyboard pops up, label moves and image changes fine. The issue in your program has to be something simple, but it isn't the above code.
Now that we've got iOS6, whenever I see posts about changes to frame coordinates not seeming to behave properly when done via code, I immediately suspect the Autolayout settings:
Make sure you uncheck that, because otherwise constraint based logic will override any attempts to manually adjust settings via code. (Or, if you want to use Autolayout, rather than setting frame coordinates, programmatically adjust your constraints to achieve the desired result.)
Anyway, it sounds like that was you issue. Glad you solved it!