I have a UITableViewCell in which I'm trying to make 1 cells separators height larger than the rest. I tried the following:
UIView* separator = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 2)];
separator.backgroundColor = [UIColor blackColor];
[cell.contentView addSubview:separator];
That works, but results in the following look:
The separator line for all the cells are set to red. In the picture above, you can see the red above the black. How can I remove the red for that cell?
I tried: cell.separatorInset = UIEdgeInsetsZero; and that didn't do anything.
Use table view separator style property to remove default separator,
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
This will remove default separator and you can use your own. Make sure that you remove custom separators properly as cell view is reused.
You cannot draw your own separator and use the built-in separators - well, you can, but you will see both of them, as you have clearly shown. If you are going to draw your own separator, tell the cell or table view not to supply separators at all.
first of all remove the default UITableViewCellSeparatorStyle to none as below..
[tableview setSeparatorStyle:UITableViewCellSeparatorStyleNone];
and after that use your own separator..
Related
I have attached an image of cells in a table view, and you can notice the 2 separator lines in the middle are a tiny bit thicker/darker than the 2 outer lines. I want the lines to all be consistent, and the color/thickness of the outer two lines. I could not find a solution, so I am wondering if anyone knows of any. I figure it would be a simple solution, but I haven't been able to figure it out. Thanks guys.
Select your UITableView from xib or storyboard, then make the UITableView separator to None.
See the image
Then place a UILabel with the width same as of UITableViewCell and height=1 in the bottom of your cell, clear the text of the label and set the backGround color as per your wish, this will solve your problem.
Hope this helps you.
Create a custom separator Line Programatically:
UIView *separatorLine = [[UIView alloc] initWithFrame:
CGRectMake(0, cell.contentView.frame.size.height - 1.0,
cell.contentView.frame.size.width, 1)];
separatorLine.backgroundColor = [UIColor blackColor];;
[cell.contentView addSubview: separatorLine];
or you can add a image view for separator in custom UITableviewCell in UI
I try to use setSeparatorStyle=UITableViewCellSeparatorStyleNONE;
And it works but I am disappointed because it lets all the separator disappear, this is not what I want. I want to have cell 1, 3 and 4 have separator, while cell 2 separator needs to be hidden. How can i do that?
You can Hide tableView's standard separator line
First use
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
You can Change hight/width/color/image of UIView for set your separatorLine.
Add custom separator to add UIView of 1px height in cell:
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];
and in index 2
Cell.separatorLineView.hidden = TRUE;
SeperatorStyle property is assigned to the UITableView. So for customization first of all set
[tableview setSeparatorStyle=UITableViewCellSeparatorStyleNone]
//thus the default seperator will be hidden.
Now insert a view having width, the same as cell width, height 1, and color separator preferred color. thus by giving reference we can show or hide this seperatorView accordingly. Seems bulky, but simple.
setSeparatorStyle=UITableViewCellSeparatorStyleNONE; //remove all separator
2.the contentView of Cell call the method addSubview ,the subView is a image(line is bottom at a background image) or a view whose height is 1px.
View the subView as a separator .
3.design a property for a cell, then change the property in the method cellForRowAtIndexPath() According to the property, you can determine if the separator is Hidden in method awakeFromNib
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 have a problem of the implementation of UITableViewCell's separator.
As you can see from the screenshot, there is a white gap visible before the separator, I think that is because I set the bg colour of the cell as light grey and also I put the inset of the separator as 53.
My first attempt was instead of using the separator, I was trying to draw the lines at the end of the cell by my self. But since on selection of the row the content of the row get updated, and there is a lot of issue regarding the calculation of the height of the cell.
So basically it is really hard for me to draw the line pixel precise at the end of the cell.
This left me the option to access the cell's separator's view, which currently not aware of any easy way, and fill the gap with my default background colour of the table.
My question is, how can I access the separator view
Or
Do I have any other alternatives to implement what I want?
Thank you very much.
UITableView doesn't provide APIs to access or modify the cells separator view directly. However, it has methods to change it's color, style, etc. Most of the times, though, the only solution for a custom separator is to draw it yourself, or better, to set the cell's backgroundView property to a simple view with a line subview or layer in it (a subview, although has some overhead, gives you the flexibility of autoresizing automatically using autoresizing masks or auto layout).
e.g.
UIView *backgroundView = [[UIView alloc] initWithFrame:cell.bounds];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(backgroundView.bounds) - 1, CGRectGetWidth(backgroundView.bounds), 1.0f];
[lineView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin)];
[backgroundView addSubview:lineView];
cell.backgroundView = backgroundView;
Use this workaround:
Put UIImageView at bottom edge of cell and you can set image as per your requirement
STEP 1: Set divider as per image
STEP 2: Set Separator style to none
Since iOS 7 you can use this
cell.separatorInset = UIEdgeInsetsZero;
I'm customizing a Tableview ..
I want to hide the top seperator line separating on the first cell. Any ideas how to do this?
Configure TableView with no Separators, and then add custom image at the bottom of every cell which will look same as separator, so you can achieve this functionality.
UITableView has
#property(nonatomic) UITableViewCellSeparatorStyle separatorStyle;
#property(nonatomic,retain) UIColor *separatorColor;
So try this
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
or
tableView.separatorColor = [UIColor clearColor];
And after that you should customize all of your cells with your own separators.
Simply add view with autoresizing mask flexible top margin and flexible width
Don't forget to add it to cell.contentView
Actual color of separator is [UIColor grayColor];