How high is the spacing between UITableViewCell? - ios

Anybody know how big is the spacing between UITableViewCells in points ? That is I would like to know whether there are any screen spaces allocated between cells in an UITableView and how high are they, in each of these separator styles:
UITableViewCellSeparatorStyleNone – is it 0pt ?
UITableViewCellSeparatorStyleSingleLine – is it 1pt?
UITableViewCellSeparatorStyleSingleLineEtched – is it 1pt or 2pt?
The problem I'm currently facing is that I have a variable-height cells and I need to calculate how high a group of cells may be. Currently I'm using UITableViewCellSeparatorStyleSingleLine separator style and assuming that the inter-cell spacing is 1pt high but my calculations are often off.
That is, supposed that there are three cells, each 40 pt high, my assumption is that the total height will be 40 + 1 + 40 + 1 + 40 = 122 points high.
Questions are:
Is it true that a single line separator takes 1pt height between the cells?
If not, what is the height of the separator line, if any space is allocated at all (i.e. doesn't "eat" into the adjacent cell's space.
Thanks in advance.

This is a problem you can solve very easily by taking a screenshot from interface builder and then measuring it in Photoshop, however I've saved you the trouble:
The separator is not added to the the height of the table cell - it is drawn in front of the cell, so if your table cell height is 44 (the default) then the combined height of two cells will be 88, regardless of which separator style you choose.

Related

What size in cells is A4?

I'm trying to create a Google Sheets template that is exactly A4. The reason for that is I need to insert a picture in there that is absolutely placed and sized.
So, I'm figuring that since A4 is 210x297mm and Google Sheets default resolution is 96dpi, I need 793.59x1122.363 pixels.
Since a cell is 100x21 pixels, I need 7 cells horizontally + an additional cell that is 93 pixels large and 53 cells vertically + a cell that is 9 pixels high.
Which prints too big (A4, portrait, Scale Normal 100%, Margins 0,0,0,0):
too big
If I manually adjust the size of the cells to get a complete grey area without white lines on a single page, like this:
perfect size
I need 7 cells + one cell that is 85 px large x 53 cells + one cell that is 8 px high.
Note that (53*21+8)/785 = 1.428, which is not sqrt(2), the standard A4 ratio.
Why ? Thanks!

Horizontal Collection View with different width cells

I have a UICollectionView where the width of the cells is dynamic based on text. When I set a spacing of 5px between all cells, this is the distance between the 2 longest cells but all the other ones are a lot more spaced.
I need the spacing to be always the same, even when the cells are very small or very big.
Any idea on how to achieve this?
So far I'm setting the minimumLineSpacingForSectionAt and the size of the cell is calculated based on the width of the text.

iOS - UIImage + UILabel Constraint Conflict In UITableViewCell

In my app, I use a UITableView to display articles for the user. I have two types of UITableViewCells; one where an article doesn't have an image, and another where an article does have an image.
Both types of UITableViewCells have a title UILabel and a description UILabel. I have the numberOfLines of the title UILabel set to 0 since some article title can be long or short. This is the determining factor for the height of the UITableViewCell, since I'm using UITableViewAutomaticDimension.
It shows up perfectly in the case when an article has no image like so:
However, in the case where an article has an image, it's not working as I need it to. These are my UIConstraints:
Article Image View
0 pixels from the right, top, and bottom of the cell
width constraint of 90 pixels
Title Label
numberOfLines is 0
8 pixels from top and left of the cell
8 pixels from left of Article Image View
Description Label
numberOfLines is 1
8 pixels from left of the cell
0 pixels from bottom of Title Label
8 pixels from left of Article Image View
8 pixels from bottom of the cell
It shows up like this:
This is very frustrating because my constraints look logical enough to be doing the job correctly.
I need my layout to look like how the Pocket app is doing it like so:
Any ideas on what I'm doing wrong? Any help or advice would be appreciated. Thanks.
*****UPDATE*****
On the advice of #kirander, I have changed the content compression resistance priority of my UIIMageView to 250, which helped me get this result:
Is there any way to minimize the leftover space in the Title Label? I need the Title Label's height to be ONLY enough where all text fits, and not a pixel more.
I ended up solving this with the help of kirander and Mike Taverne. If you need a tight design similar to this, these were the constraints that got me what I wanted:
Article Image View
0 pixels from the right, top, and bottom of the cell
width constraint of 90 pixels
Content Compression Resistance Priority -> 250
Title Label
numberOfLines is 0
8 pixels from top and left of the cell
8 pixels from left of Article Image View
Description Label
numberOfLines is 1
8 pixels from left of the cell
0 pixels from bottom of Title Label (I mentioned this in the original question, but it turned out that I didn't have it...correcting that moved me toward my solution)
8 pixels from left of Article Image View
8 pixels from bottom of the cell
These constraints gave me the following tight design:

Determine UILabel height for centering when using adjustFontSizeToFitWidth

I have the following cell design where the numeric label shrinks and the "Overall" label is directly underneath.
I have properly set the adjustFontSizeToFitWidth and minimumFontSize properties. The font is resizing correctly. However, anchoring the numeric label to the bottom is challenging. Particularly when the font shrinks the gap between the two labels widens and does not appear vertically centered.
I have tried sizeToFit, sizeThatFits, and using the font's pointSize. All unsuccessfully.
I am aware of sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:, but don't understand why I would need it in combination with adjustFontSizeToFitWidth.
Ah, so you want to position the UILabels in the middle of the container view (both horizontally and vertically)?
I have rephrased my answer so it will make more sense to future readers.
My code is assuming that you have the 3 IBOutlets set up:
UIView *containerView; //Your nice view containing the two textfields.
UILabel *points; //The label containing the number.
UILabel *overall; //The textfield containing the text 'overall'.
You could simply set the frame of the labels after assigning the text and calling the sizeToFit.
This first line positions the UILabel points, the only change being that the y coordinate is half of containerView subtract half of the height of itself.
points.frame = CGRectMake(points.frame.origin.x, (containerView.frame.size.height / 2) - (points.frame.size.height / 2), points.frame.size.width, points.frame.size.height);
To position the overall accordingly - say there is a distance of say 6 between the number and overall labels:
int space = 6;
overall.frame = CGRectMake(overall.frame.origin.x, points.frame.origin.y + points.frame.size.height + space, overall.frame.size.width, overall.frame.size.height);
Having read your comments, I think you are after this solution. If you want both UILabels to appear in the middle; subtract (overall.frame.size.height / 2) + (space / 2) from the y value of points like so (with the code of number 2 beneath it):
int space = 6;
points.frame = CGRectMake(points.frame.origin.x, ((containerView.frame.size.height / 2) - (points.frame.size.height / 2)) - ((overall.frame.size.height / 2) + (space / 2)), points.frame.size.width, points.frame.size.height);
overall.frame = CGRectMake(overall.frame.origin.x, points.frame.origin.y + points.frame.size.height + space, overall.frame.size.width, overall.frame.size.height);
The final point will produce an output like this image. As you can see the blue line is half of the whole image, and intersects the black rectangle (which is snuggly around the two labels) at its middle point. I hope this is what you were after.
Instead of using two labels, use CATextLayer instead. You will be easily able to make one part BOLD and the other normal. plus position and adjusting size for One layer will be easy relative to placing two labels. shadow setting, line break mode, fonts you will be able to adjust everything beautifully :)

What components make up a UITableView?

I am trying to resize a grouped tableview 'tv', knowing that a new section (with a single row) is going to be added.
I thought that I could increase the height using:
newHeight = tv.frame.size.height + tv.rowHeight + tv.sectionFooterHeight + tv.sectionHeaderHeight;
but this seems to be too little (by about 30 pixels using default heights).
Am I missing some other part of the tableview? Maybe some buffer space between elements?
tv.sectionHeaderHeight and sectionFooterHeight both report a height of 10 - this seems fishy to me since the header looks at least twice the size of the footer.

Resources