1> I have UITableViewCell and UITableViewCell subclass cell both in my tableview. Setting SeparatorInset on UITableViewCell subclass cell is not working?, but If I set it on UITableViewCell it works fine.
2> Apple doc regarding SeparatorInset says:
You can use this property to add space between the current cell’s
contents and the left and right edges of the table. Positive inset
values move the cell content and cell separator inward and away from
the table edges. Negative values are treated as if the inset is set to
0.
Only the left and right inset values are respected; the top and bottom
inset values are ignored. The value assigned to this property takes
precedence over any default separator insets set on the table view.
a. If I set [cell setSeparatorInset:UIEdgeInsetsMake(0, 100, 0, 0)]; on UITableViewCell it push the content towards right
but setting [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 100)]; on UITableViewCell push only separator towards left not the content, why?
1)
In UITableViewCell you have subviews which position you cannot edit directly (title, accessoryView, ...). Here comes separatorInset which enables you to adjust position of those subviews (in other words separatorInset is considered during position calculation of those subviews).
In custom UITableViewCell subclass you are positioning your own subviews, so unless you specifically consider separatorInset during calculation of their position, it has no effect.
2)
separatorInset does not 'push' the content to left/right, rather adds (virtual) insets to container in which they are positioned. So if e.g. you only have title that does not stretch to full width of the cell (-100) you would not see any difference after adding right inset.
Related
as the title states, I'm wondering what the standard insets are for the default iOS tableview is. I'm using a different library and want to set the insets equal to the default table view cells.
You can use insets property given in storyboard or you can give insets programmatically.
Like,
[self.tableView setContentInset:UIEdgeInsetsMake(108, 0, 0, 0)]; // Top, Left, Right, Bottom
I am trying to set the height of a UITableViewCell based on its children's constraints. Basically, here's the layout:
UITableView > UITableViewCell > NestedUIView (with a computable height)
I started by setting the top, bottom, left, and right constraints of the NestedUIView to be 10px off from the UITableViewCell. Then, I tried adding a height constraint (which in my head would force the UITableViewCell to expand to fit that content. Of course though, it causes a constraint conflict and fails.
This seems like it should be trivial, what am I doing wrong?
Add this to your viewDidLoad method
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 42;
This will tell the table to use the cell constraint's to determine the height.
I am using UITableView in my project. i am increasing and decreasing the height of UITableView cell on the continuous taps. In other words i am toggling the height of UITableViewCell on taps. Now i want to keep the UITableViewCell textLabel at the same place which is at the top. But when i increase the height of UITableViewCell the textLabel come in the middle of the cell.
To avoid this is am using sizeToFit for cell.textLabel but it not working... any help...
The easiest way to do this is add Auto-Layout constraints to the default TextLabel programmatically. I would pin it from the leading edge, trailing edge, and bottom edge of the Superview (in this case being the cell).
try
label.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
and don't do the size to fit. What this will do is change the distance from the bottom of your label to the bottom of the cell. In other words, it will keep the distance from the top constant.
I have a UITableView in a Storyboard where I have configured the Separator Inset to custom (0,0) as well as for the Prototype Cell (0,0).
While I can see the separator line is now 100% the width of the table, the UIImageView (subclassed to AsyncImageView) is still positioned to the right by 15px.
I've tried setting it on the table view on load and when the cell is constructed from a dequeue but I'm still seeing a padding on the left. (I've queried the cell and table and the inset and frame has zero left padding).
Is there anything I'm missing?
You have to subclass UITableViewCell and call layoutSubviews from your newly created UITableViewCell class, in the layoutSubviews method, use
- (void)layoutSubviews{
[super layoutSubviews];
self.imageView.frame = CGRectMake(0, 0, 50, 50); // override frame of your choice
}
I have a grouped tableView in my iPad-app, and I've been trying to set cell.imageView.center = cell.center to center the image instead of putting it to the leftmost position. This is apparently not possible without a subclass of the UITableviewCell(If someone could explain why, that'd also be appreciated.. For now I just assume they are 'private' variables as a Java-developer would call them).
So, I created a custom tableViewCell, but I only want to use this cell in ONE of the rows in this tableView. So in cellForRowAtIndexPath I basically write
cell = [[UITableViewCell alloc]initWith//blahblah
if(indexPath.row == 0)
cell = [[CustomCell alloc]initWith//blahblah
This is of course not exactly what I'm writing, but that's the idea of it.
Now, when I do this, it works, but the first cell in this GROUPED tableView turns out wider than the rest of them without me doing anything in the custom cell. The customCell class hasn't been altered yet. It still has rounded corners though, so it seems it knows it's a grouped tableView.
Also, I've been struggling with programmatically getting the size of a cell, in cellForRowAtIndexPath, I've tried logging out cell.frame.size.width and cell.contentView.frame.size.width, both of them returning 320, when I know they are a lot wider.. Like, all the rows are about 400 wide, and the first cell is 420 or something. It still writes out 320 for all the cells..
This code will not work for a couple of reasons:
cell.imageView.center = cell.center;
Firstly, the center is relative to its superview. I believe the cells superview is the tableView. The imageView's superview will be the content view of the cell. Therefore the coordinate systems are different so the centens will be offset. E.g. the 3rd cell down will have a center of 0.5 widths + 3.5 heights. You should be able to ge around this issue by doing:
cell.imageView.center = CGPointMake( width / 2 , height / 2 );
The second issue is related to how the table view works. The table view manages its cells view's. The width of a cell is defined by the table view's width and the height is defined by the table view's row height property. This means the cell itself has no control over its size.
You can however size its subviews, but you must do this after the cells size has been set (otherwise you can get strange results). You can do this in layout subviews (of the custom UITableViewCell class). See this answer.
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.frame = ....
}
When layoutSubviews is called the cells frame has been set, so do your view logging here instead of cellForRowAtIndexpath.
As for the GROUPED style. Im not sure if this is designed to work with custom views. I suspect it sets the size of its cells to its own width minus a 20 pixel margin on each size, then applies a mask to the top and bottom cells in a section to get the rounded effect. If you are using custom view try to stick with a standard table view style.