Custom UITableViewCell resize label when setEditing is called - iphone

Okay here is a picture:
I've got custom UITableViewCell with UILabel.
It's obvious I should resize my custom UILabel in -setEditing method, but how to exactly calculate how much to resize it? And is there efficient way to resize reused cells?
Thanks!

You don't have to do anything in setEditing method if you have the right autoresizing mask:
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;

So the first question is how are you adding the label to the UITableViewCell? If you are adding it to the cell's view, then that is where your problem begins.
UITableViewCells have a contentView property. This contentView is responsible for resizing its contents when the cell enters editing mode. It knows how to do this. The cell's view property does not. So, first you need to add your UILabel as a subview of the cell's contentView in initWithStyle:. The cell doesn't actually know how big it is in initWithStyle:, though, so you can set the frame of the label in layoutSubviews.
As for resizing the cell, you can do this in tableView:heightForRowAtIndexPath:
In this method, you can check the indexPath of the row and configure the height appropriately.

Related

UITableViewCell Background Color?

I have done a fair bit of googling on this and I can't find the right solution. I have a UITableView of which I want to change the colour of the background of the cells. I have found solutions to doing this but it only deals with cells which have content or data as it were.
I need to colour the background of those unused cells as well.
Try setting the background colour of the tableView itself. Those "empty cells" at the bottom aren't really cells at all - they're just separator lines drawn over the background.
Even though UITableViewCell inherits from UIView, changing the backgroundColor property of the cell itself won't do anything. You need to change the background color of the cell's contentView, such as
cell.contentView.backgroundColor = [UIColor greenColor];
This is because the subviews of a UITableViewCell are actually subviews of the cell's contentView, because the contentView knows how to resize its subviews if a cell is put into editing mode; the cell itself doesn't know how to do that.
I'm not sure what you mean by unused cells. If you tell your tableView there are 10 cells and you only provide content for 8 of them, you'll still have 10 green cells, if that's what you mean by "unused".

Height change of UITableViewCell causes resizing of contentView and accessoryView in cell

I'm using this solution to animate a change of height in a UITableViewCell. I've set a UIButton as the accessoryView of the cell, which triggers the height change. The animation works fine, but if the cell gets larger in height, the ratio in width of contentView and accessoryView changes. In specific, the accessoryView gets wider, the contentView narrows. The change of ratio has got the effect, that the UIButton in the accessoryView moves a bit to left. But for me, it should stay in the same x-Position. Anyone got a clue? Thanks for your answers :)
Made a workaround by placing a UIButton in the contentView of the cell. So solved!

is there any way to change default frame sizes of an imageView, textLabel and detailTextLabel of cell?

I am trying to change frame sizes of an imageView. textLabel and detailTextLabel of UITableViewCell property on inside the UITableView. I tried with change the frame size, resizing mask, resizing subviews and so on, but there is no use. Is there any way to change default frame size? and I am using UITableViewCellStyleSubtitle.
Note: My images took their own image size.
I think is possible with a UITableViewDelegate method:
– tableView:willDisplayCell:forRowAtIndexPath:
you can set frame sizes, position, etc. Basically any layout should have effect there.
or you can subclass UITableViewCell and override layoutSubviews: method (don't forget to call [super layoutSubviews]; first)
Actually I am doing the second approach and works excelent.
Hope this helps ;)
In my opinion, the right way is to redesigned the cell.
2 possibilities:
Programmatically in tableView:cellForRowAtIndexPath: (see iOS guide)
with a custom UITableCellView (see iOS guide)
And for the cell height: tableView:heightForRowAtIndexPath: of the delegate

Accessing grouped UITableView section view?

Basically I want to "cut the corners" of the first cell imageview and the last cell imageview to match the curved corners on the grouped tableview section.
I was given the advice to do this by setting the view's masksToBounds property to true?
Anyone know how to access this view? Doing cell.superview doesn't work. cell.contentView.superview doesn't work and cell.backgroundView.superview doesn't work.
Anyone have any ideas?
There is no section view. A cell's superview is the UITableView itself.
The rounded corner drawing is done by UITableViewCell's backgroundView, and backgroundView isn't in imageView's view hierarchy (contentView and backgroundView are siblings—their superview is the Cell itself), so unfortunately masksToBounds won't work.

how to add UIImage view inside table cells for iphone

i want to add a UIimabeView inside table view cells to disyplay images (5 images on tap)
no is it pissible to show Images in table cells??/
Yes it is possible. You can add it to the cell's contentView in TableView's cellForRowAtIndexPath method.
Alternatively, you can create a custom tableview cell if you want to avoid the hassle of adjusting the imageView's positions in the code and you can just set the images for these image view in the cellForRowAtIndexPath method.
If you want to add views to a cell, add them to the contentView of the cell:
UIImageView *myImageView = ...;
[cell.contentView addSubview:myImageView];