I am creating a custom UITableViewCell using the Storyboard editor. I've got several components in this cell, but the biggest is a UILabel that is displayed at the top. This label should be left-aligned, however I'm finding that when I run the app in the simulator to test, the text is centered. I've tried specifying the alignment manually, but it always centers itself.
Is there something I need to do to get this working properly in a custom UITableViewCell? I've never encountered anything like this before.
Try using Debug->Color Render layers in the simulator to see if your text is actually centered, or the UILabel moved. Try removing the outlet if any, to prevent anything from tampering with it and see if it helps diagnose.
If the colored layer is offset, make sure you added proper constraints to the label (or autoresizing masks). Anchor it to at least left and top and leave the other 2 sides free.
Related
I have some issue with labels layout using storyboard.
Left view snapped to labels trailing constraint, and centered according to text, and nothing more. So problem appears when I try to set different text to label, (when text contains number of characters greater then in text on story board). After text has been setting label does't resize it's frame.
Here, how it looks in runtime:
I have the same issue with other all labels in project, they are don't resize in runtime, but They should. Here is how it should looks like :
I'v already tried to add layoutIfNeeded() and sizeToFit() to those labels, but it has no effect. I made another project, with pretty same label and constraints, and there it works fine, as should. But not in this project.
What problem could be in?
It could also depend on when you're setting the text of the label.
If you're setting the text in viewDidLoad try doing it in viewDidAppear.
I have a UITableViewCell subclass as normal, and have some views/outlets/constraints:
I can assure you there's nothing special here. An image view and two labels, related by regular horizontal/center Y constraints, and the image view has leading/top constraints. Pretty simple and regular stuff.
However, when I run, I get this:
Image (I've also tried with different background color, it's there at top left of the cell, just with a white background) and the both labels are stuck at the top left of the cell. I've been programming iOS/autolayout for years and this is the first time I'm seeing such a thing.
There aren't any broken constraints on the log either. When I open view debugger, I see this:
While all the size constraints are there, all the superview/inter-view constraints are gone and they are being reported as "position ambiguous". The constraints are not even there. Why would this happen? I've double checked the constraints in Interface Builder: they are at 1000 priority, are installed, and are not placeholders:
Moreover, I've got other cells (with slightly different design) that inherit from the same class, and they are perfectly working with a different nib. In fact, I've directly copied the cell from another nib so it's the replica of a perfectly one either.
What would be going wrong?
I use auto layout and building app for iOS 7. I am using a custom UITableViewCell. I want to display an UIImageView inside it with some margin from contentView's borders. So I have taken an UIView which has margin from contentView's borders. UIImageView that I want to display is put into this UIView with all edges touching its superview.
Now, issue is the UIImage (green background) which is set to UIImageView is not displayed perfectly. By perfectly I mean that it is displayed but bottom 1px is not displayed. I have set image in storyboard and it looks perfect there as shown below.
But when I run the app then it looks as shown below. Concentrate on bottom black line which is clearly visible in storyboard but not when I run the app.
Please note that cell height in storyboard is 95pts. Image height is 77pts (non-retina). Also when I scroll cell up and down then I see that during scrolling this bottom line is visible, but that time top lines is not properly visible.
I have noticed such sub-pixelization issues when the simulator is in less than 100% scale size.
Especially on scrolling, when you notice it's sharpness fluctuates, it basically indicates that it's not being rendered properly.
So, test this scenario in the iOS simulator in 100% scale size
command+1
or...
simulator menu > window > scale > 100%.
Alternatively, test this scenario on a device as well since it'll be more "realistic".
If the issue persists then give even numbers in the frame size and/or avoid float values *(but don't quote me on this)
I had the same issue with autolayout and CustomCell with a specific image.
What I did was ticking clip subviews, and the problem was gone. You can tick it in IB by checking imageView and go to Attributes Inspector:
Considering that your autolayout is correct, this question may help.
But anyways give it a try and give me feedback
I am not sure what is going on and how to handle this. I have a UIView in a cell and I set the constraints using IB and for some reason it stretches out to the end of the cell. How can I stop it from stretching.
And here is the result:
I am dynamically injecting a stepper control but as you can see the UIView stretches to the end of the cell. I tried pin width then it completely messes up everything and does not even display the UIView.
Here is the screenshot of constraints:
Okay, let me draw some distinctions here.
The trivial way to this is you always have the stepper in the cell (and no UIView). For those cells where we are not supposed to see the stepper, you set its hidden to YES; for those cells where we are supposed to see it, you set its hidden to NO. That is what I would do.
The programmer way to do this is you don't have any blue UIView in your cell at all. You add the stepper in code, and you also provide its constraints in code to position it. You said:
so I don't have to hardcode the coordinates
But adding constraints in code is not "hard coding" the coordinates. With constraints, you describe the position conceptually in terms of insets from the superview, and as the superview resizes, you are still correctly positioned. So there is no philosophical objection to adding the stepper and its constraints, and it is just laziness not to do that.
The lazy but wasteful way is to do what you are doing, i.e. add the blue UIView in the nib as a guide. Even if you do use the blue UIView as a guide, though, you should be able to get this right if your constraints are right. I just tried this and I was not able to reproduce the problem: my blue view appeared in my cells in the same place where it appears in Interface Builder.
The instant solution is don't use Autolayout in the nib from which a UITableViewCell is drawn — i.e. uncheck "Use autolayout" in the file inspector for this nib. You will thus use old-fashioned springs-and-struts (autoresizing) to position the subviews.
This isn'an a question, just a results log on an issue I had with XCode 4.5 storyboards and dynamic height UITableCell with a UILabel.
The issue was; the initial display of a cell would only show part of the resized UILabel contents, and that the visual UILabel was not resized. It would only display correctly after scrolling off the top of the Table and back down.
I did the calculations in hieghtForRowAtIndexPath and sizeToFit the UILabel in rowAtIndexPath. The sizes where coming up ok in debug, but the device was not updating the display with the correct size and UILable.text value.
I had created the dynamic UITableCell in a storyboard. However, I had set the width and height to a nominal value (290x44). It turns out, this was causing my issues.
I set the width and height to zero (0) in the story board, and everything started working correctly. (i.e. the UILabels displayed at the correct size with full content).
I was unable to find anything online on this issue, except for some references to creating the custom table cell with a frame of zero. Turns out, that was really the answer (for me).
I ran into the same problem and solved it by simply unchecking "Use Autolayout" in storyboard. You might want to give it a try.
I was unable to find anything online on this issue, except for some references to creating the custom table cell with a frame of zero. Turns out, that was really the answer (for me).