How do you set the separatorInsets of a table view cell back to their default values programmatically? I want to change them for some cells but not others.
Use following way :
if (indexPath.row == {your row number}){
cell.separatorInset = UIEdgeInsetsMake(0, 15, 0, 0);
}
In iOS7 table view has default 15 left inset for separator,you can change it as per your requirement by using above code.
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
According to documentation,
UITableViewCellSeparatorStyleSingleLine
The separator cell has a single line running across its width. This is the default value. Available in iOS 2.0 and later.
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 want to add a cell in the bottom that shows only if the app is loading more results when the user scrolls to the bottom of a tableview. I already did that. The problem is that it's a cell. So when I scroll down even further, the separator shows that it's just another cell in the table. I want to hide that. I have to change that cell's separator color, how do I do that to a particular cell? Also, Where/when do i do that?
I realize that if I change that cell's color (let's say it's #5), when I get the results and load them in, won't that also result in cell #5 still having an invisible separator? So how do I set it back to the default color? More particularly how do I get the default color for a tableviewcellseparator programmatically?
Thanks
Here's a simple trick: you have to add en empty UIView inside your UITableView in Storyboard. The set the height = 0.
The last separator of the UITableView magically disappears.
Edit:
You will also need to edit your cellForRowAtIndexPath: like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"identifier"];
if (indexPath.row == [self tableView:tableView numberOfRowsInSection:[self numberOfSectionsInTableView:tableView]-1]-1) {
//this is the last cell
cell.separatorInset = UIEdgeInsetsMake(0, cell.bounds.size.width, 0, 0);
} else {
cell.separatorInset = UIEdgeInsetsMake(0, 0, cell.bounds.size.width, 0);
}
return cell;
}
Separator colour is a property of the table view, you can get or set it like so:
self.tableView.separatorColor = UIColor.blackColor()
But I don't think you cannot change the separator colours of a individual cell.
If you truly need that level of customization, you should probably just draw the separator bar yourself as, for example, a thin UIView at the top of the cell. Then you can change its appearance to whatever you want.
What I'd like to do is remove the separator for a single cell in a tableview. I'd like to keep the others ones as they are but I can't seem to find a way to do it.
I thought I could adjust the insets but from what I can see, these aren't the insets that I am trying to modify.
One easy way to get the same effect, but not answering exactly your question, is to disable UITableView's separators and adding a 1px-height UIView to the prototype cells you want to have it.
Yes, you can set cell separator inset in willDisplayCell.
if (indexPath.row == HideTheRowSeparator) {
cell.separatorInset = UIEdgeInsetsMake(0, tableView.bounds.size.width, 0, 0);
}
Hi I'm new to ios development. I am developing an application in which I am using UITableView.
Tableview contains some cells with separator line and others without separator line.
Can any one please tell me how can I remove separator line for specific cell?
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, cell.bounds.size.width);
Above code works for iOS 7. How can I achieve this in iOS6?
Any help is appreciated
You can just add a UIView with the same background color as you want your separator line to be at the top of your UITableViewCell layout, make its height one pixel (it will be the same as a line) and its width the same as your cell width (cell.frame.size.width). After this in your cellForRowAtIndexPath just set hidden property of this to YES for the cell you don't want it to be shown and hidden = NO for those you want. It is a simple solution which will work in any iOS version. But if will add your custom separator don't forget to disable default separators for all tableview
In order to have only specific cells with separator you have to draw separator lines for those cells. In my view set the separator style to none and then draw you custom separator for the desired cells.
You can follow this link for custom separators
Basically what u need to do is add a custom view as follows:
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];/// change size as you need.
separatorLineView.backgroundColor = [UIColor grayColor];// you can also put image here
[cell.contentView addSubview:separatorLineView];
to set the separator style to none use:
tableView.separatorStyle=UITableViewCellSeparatorStyleNone
If you try to change the color of the separatorLine for this. But one thing is that if you want to make the adjacent cells as a single cell then this would not be the right approach. As this will make only the UI change.
The better approach would be to adjust the size of the cell and so that you get "single cellClick events for them".
you can use the delegate for this:-
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
I am having a problem in displaying cell separator of grouped style tableView in iOS 7.
if ([projectTable respondsToSelector:#selector(setSeparatorInset:)]) {
[projectTable setSeparatorInset:UIEdgeInsetsZero];
projectTable.separatorColor = [UIColor blackColor];
}
This doesn't show cell separator. Kindly suggest
In iOS7 design. try to do the below:
[projectTable setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
and also you have to do:
[projectTable setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
You can set the 'Separator Inset' from the nib or Storyboard:
Even though it has a default value (UITableViewCellSeparatorStyleSingleLine), have you tried reseting your separatorStyle property ?
[projectTable setSeparatorStyle:UITableViewCellSeparatorStyleSingleLineEtched];