UITableView cell separator line thicker? - ios

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

Related

Increase 1 UITableViewCell separator height

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..

Gap between two UItableview cells

In my app i am using tableview with cells having images coming from server. I want to give some space or gap or line between two cells. if i use
[tableView setSeparatorColor:[UIColor blackColor]];
I am able to separate the cells but not the image view. I also want to give space or gap or line between the cell.imageviews.
I want to give gap between the cell imageviews above
For this you can use below code:
yourTableView.separatorInset=UIEdgeInsetsZero;
and if you want a custom separator, then you can use below code:
UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 2)];/// change size as you need.
separatorLineView.backgroundColor = [UIColor grayColor];// you can also put image here
[cell.contentView addSubview:separatorLineView];
here is another way you can do very easily from story board also
.
My question will be, how do you add the image to your table cell...from what i can tell your images are not in the right place, it's like you're adding the image to the table row not in the cell that spouse to be on that row, your problem is not in the separator...because its starts after your image...hope you understood my point, but who knows...may be i'm wrong...some code will be usefull

uitableviewCell Separator line

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;

How to customise the UITableView's Separator View?

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;

Can't get UILabel to show properly on top of UITableView

I am struggling to achieve what I thought was nothing but a 1' coding but apparently
adding a UILabel above my UITableView in a UITableViewController is not a piece of cake...?
Here is the code (yes basic, I know):
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 310, 20)];
[[self tableView] addSubview:label];
The result can be seen in the screenshot below, the label on the top right is just half displayed, saying "Balance..."
Please note that if I try to change CGRect origin.y or size.height the UILabel is not displayed at all.
I also tried adding the following, with no change in result:
[[self tableView] bringSubviewToFront:balanceLabel];
I don't care if the UILabel is scrolled up when scrolling up the UITableView, I want it to stick with the first section header.
I know this can be achieved in other ways, using a custom UIView for the header, changing to UIViewController or using a .xib, but really I would like to understand why this happens.
Thanks for any help.
F.
It does look like the header is hiding your label, maybe you could try setting the header background to clearColor. Since you have no control on the table view loop I suspect that after your addSubView somewhere the table builds its own header and does another addSubView.

Resources